Socket.Bind Method (EndPoint)
Associates a Socket with a local endpoint.
Assembly: System (in System.dll)
localEP is null.
An error occurred when attempting to access the socket. See the Remarks section for more information.
The Socket has been closed.
A caller higher in the call stack does not have permission for the requested operation.
Use the Listen method. You do not need to call before using the Connect method unless you need to use a specific local endpoint. You can use the method on both connectionless and connection-oriented protocols.method if you need to use a specific local endpoint. You must call before you can call the
Before calling IPEndPoint from which you intend to communicate data. If you do not care which local address is assigned, you can create an IPEndPoint using IPAddress.Any as the address parameter, and the underlying service provider will assign the most appropriate network address. This might help simplify your application if you have multiple network interfaces. If you do not care which local port is used, you can create an IPEndPoint using 0 for the port number. In this case, the service provider will assign an available port number between 1024 and 5000., you must first create the local
If you use the above approach, you can discover what local network address and port number has been assigned by calling the LocalEndPoint. If you are using a connection-oriented protocol, LocalEndPoint will not return the locally assigned network address until after you have made a call to the Connect or EndConnect method. If you are using a connectionless protocol, you will not have access to this information until you have completed a send or receive.
If a UDP socket wants to receive interface information on received packets, the SetSocketOption method should be explicitly called with the socket option set to PacketInformation immediately after calling the method.
If you intend to receive multicast datagrams, you must call themethod with a multicast port number.
You must call the ReceiveFrom method.method if you intend to receive connectionless datagrams using the
If you receive a SocketException when calling the method, 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.
Available since 10
Available since 1.1
Windows Phone Silverlight
Available since 8.0