Socket.LocalEndPoint Property

July 28, 2014

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.

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

public EndPoint LocalEndPoint { get; }

Property Value

Type: System.Net.EndPoint
The EndPoint that the Socket is using for communications.

ExceptionCondition
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.

Windows Phone OS

Supported in: 8.1, 8.0

Show:
© 2014 Microsoft