Socket.LocalEndPoint Property
[ This article is for Windows Phone 8 developers. If you’re developing for Windows 10, see the latest documentation. ]
Gets the local endpoint that contains the local IP address and port number to which the socket is bound. This is the endpoint that the socket is using for communications.
Assembly: System.Net (in System.Net.dll)
| Exception | Condition |
|---|---|
| SocketException | An error occurred when attempting to access the socket. If you receive a SocketException, use the SocketException.ErrorCode property to obtain the specific error code. |
| ObjectDisposedException | The Socket has been closed. |
The LocalEndpoint property is null if the Socket has not been bound yet using the Bind method.
The LocalEndPoint property gets an EndPoint that contains the local IP address and port number to which your Socket is bound. You must cast this EndPoint to an IPEndPoint before retrieving any information. You can then call the Address method to retrieve the local IPAddress, and the Port method to retrieve the local port number.
The LocalEndPoint property is usually set after you make a call to the Bind method. If you allow the system to assign your socket's local IP address and port number, the LocalEndPoint property will be set after the first I/O operation. For connection-oriented protocols, the first I/O operation would be a call to the ConnectAsync or AcceptAsync method. For connectionless protocols, the first I/O operation would be any of the send or receive calls.