Socket Constructor

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

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

'Declaration
Public Sub New ( _
	addressFamily As AddressFamily, _
	socketType As SocketType, _
	protocolType As ProtocolType _
)

Parameters

addressFamily
Type: System.Net.Sockets.AddressFamily
One of the AddressFamily values.
socketType
Type: System.Net.Sockets.SocketType
One of the SocketType values.
protocolType
Type: System.Net.Sockets.ProtocolType
One of the ProtocolType values.

ExceptionCondition
ArgumentException

A parameter was invalid.

SocketException

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

The addressFamily parameter specifies the addressing scheme that the Socket class uses, the socketType parameter specifies the type of the Socket class, and the protocolType parameter specifies the protocol used by Socket. The three parameters are not independent. Some address families restrict which protocols can be used with them, and often the Socket type is implicit in the protocol. If the combination of address family, Socket type, and protocol type results in an invalid Socket, this constructor throws a SocketException.

NoteNote:

If this constructor throws a SocketException, use the 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.

The following example creates an instance of the Socket class.


' Create a socket and connect to the server
Dim sock As Socket = New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

AddHandler socketEventArg.Completed, AddressOf SocketEventArg_Completed

socketEventArg.RemoteEndPoint = hostEntry
socketEventArg.UserToken = sock
sock.ConnectAsync(socketEventArg)


Silverlight

Supported in: 5, 4, 3

Silverlight for Windows Phone

Supported in: Windows Phone OS 7.1

For a list of the operating systems and browsers that are supported by Silverlight, see Supported Operating Systems and Browsers.

Community Additions

ADD
Show: