Socket.Connect Method

Establishes a connection to a remote host.

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

Syntax

public void Connect (
         EndPointremoteEP
)

Parameters

  • remoteEP
    An EndPoint object that represents the connection to the remote host.

Remarks

If you are using a connection-oriented protocol such as TCP, the Connect method synchronously establishes a network connection between the local endpoint (specified by the LocalEndPoint property) and the specified remote endpoint. If you are using a connectionless protocol, Connect establishes a default remote host. After you call Connect, you can send data to the remote device by using the Send method, or you can receive data from the remote device by using the Receive method.

If you are using a connectionless protocol such as UDP, you do not have to call Connect before sending and receiving data. You can use the SendTo and ReceiveFrom methods to synchronously communicate with a remote host. If you do call Connect, any datagrams that arrive from an address other than the specified default will be discarded. If you want to set your default remote host to a broadcast address, you must first call the SetSocketOption method and set the option to SocketOptionName.Broadcast; otherwise, Connect will throw a SocketException exception. If you receive this type of exception, use the SocketException.ErrorCode property to obtain the specific error code. After you have obtained this code, refer to the Windows® Sockets 2.0 API error code documentation in the MSDN® Library for a detailed description of the error.

Version Information

Available in .NET Micro Framework version 2.0, 2.5

See Also

Reference

Socket Class
Socket Members
System.Net.Sockets Namespace