[This documentation is for preview only, and is subject to change in later releases. Blank topics are included as placeholders.]
Establishes a connection to a remote host.
Assembly: System (in System.dll)
If you are using a connection-oriented protocol such as TCP, the method synchronously establishes a network connection between LocalEndPoint and the specified remote endpoint. If you are using a connectionless protocol, establishes a default remote host. After you call , you can send data to the remote device with the Send method, or receive data from the remote device with the Receive method.
If you are using a connectionless protocol such as UDP, you do not have to call before sending and receiving data. You can use SendTo and ReceiveFrom to synchronously communicate with a remote host. If you do call , 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 socket option to SocketOptionName..::..Broadcast, or will throw a SocketException. If you receive 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.
If you are using a connection-oriented protocol and did not call Bind before calling , the underlying service provider will assign the local network address and port number. If you are using a connectionless protocol, the service provider will not assign a local network address and port number until you complete a send or receive operation. If you want to change the default remote host, call again with the desired endpoint.
- Full trust for the immediate caller. This member cannot be used by partially trusted code. For more information, see dd66cd4c-b087-415f-9c3e-94e3a1835f74.