Socket Constructor (SocketType, ProtocolType)

Socket Constructor (SocketType, ProtocolType)

.NET Framework 4.6 and 4.5

Initializes a new instance of the Socket class using the specified socket type and protocol.

Namespace:   System.Net.Sockets
Assembly:  System (in System.dll)

Public Sub New (
	socketType As SocketType,
	protocolType As ProtocolType


Type: System.Net.Sockets.SocketType

One of the SocketType values.

Type: System.Net.Sockets.ProtocolType

One of the ProtocolType values.

Exception Condition

The combination of socketType and protocolType results in an invalid socket.

The socketType parameter specifies the type of the Socket class and the protocolType parameter specifies the protocol used by Socket. The two parameters are not independent. Often the Socket type is implicit in the protocol. If the combination of Socket type and protocol type results in an invalid Socket, this constructor throws a SocketException.


If this constructor throws a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows Sockets version 2 API error code documentation in the MSDN library for a detailed description of the error.


This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

Universal Windows Platform
Available since 10
.NET Framework
Available since 4.5
Return to top
© 2015 Microsoft