System.Net.Sockets.Socket.RemoteEndPoint Property

Gets the remote endpoint.

Syntax

public System.Net.EndPoint RemoteEndPoint { get; }

Value

The remote 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

If you are using a connection-oriented protocol, the Socket.RemoteEndPoint property gets the System.Net.EndPoint that contains the remote IP address and port number to which the System.Net.Sockets.Socket is connected. If you are using a connectionless protocol, Socket.RemoteEndPoint contains the default remote IP address and port number with which the System.Net.Sockets.Socket will communicate. 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 remote System.Net.IPAddress, and the System.Net.IPEndPoint.Port method to retrieve the remote port number.

The Socket.RemoteEndPoint is set after a call to either Socket.Accept or Socket.Connect(System.Net.EndPoint). If you try to access this property earlier, Socket.RemoteEndPoint will throw a System.Net.Sockets.SocketException. 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