System.Net.Sockets.Socket.LocalEndPoint Property

Gets the local endpoint.

Syntax

public System.Net.EndPoint LocalEndPoint { get; }

Value

The local System.Net.EndPoint associated with the current instance.

Exceptions

TypeReason
System.Net.Sockets.SocketException
Note: For additional information on causes of the SocketException, see the System.Net.Sockets.SocketException class.
ObjectDisposedExceptionThe current instance has been disposed.

Remarks

The Socket.LocalEndPoint property gets an System.Net.EndPoint that contains the local IP address and port number to which your System.Net.Sockets.Socket is bound. You must cast this System.Net.EndPoint to an System.Net.IPEndPoint before retrieving any information. You can then call the System.Net.IPEndPoint.Address method to retrieve the local System.Net.IPAddress, and the System.Net.IPEndPoint.Port method to retrieve the local port number.

The Socket.LocalEndPoint property is usually set after you make a call to the Socket.Bind(System.Net.EndPoint) method. If you allow the system to assign your socket's local IP address and port number, the Socket.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 Socket.Connect(System.Net.EndPoint) or Socket.Accept method. For connectionless protocols, the first I/O operation would be any of the send or receive calls.

Note:

If you receive a System.Net.Sockets.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.

Note:

This member outputs trace information when you enable network tracing in your application. For more information, see [<topic://conUsingNetworkTracing>].

Requirements

Namespace: System.Net.Sockets
Assembly: System (in System.dll)
Assembly Versions: 1.0.5000.0, 2.0.0.0, 4.0.0.0