RemoteEndPoint Property

Socket::RemoteEndPoint Property

 

Gets the remote endpoint.

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

public:
property EndPoint^ RemoteEndPoint {
	EndPoint^ get();
}

Property Value

Type: System.Net::EndPoint^

The EndPoint with which the Socket is communicating.

Exception Condition
SocketException

An error occurred when attempting to access the socket. See the Remarks section for more information.

ObjectDisposedException

The Socket has been closed.

If you are using a connection-oriented protocol, the RemoteEndPoint property gets the EndPoint that contains the remote IP address and port number to which the Socket is connected. If you are using a connectionless protocol, RemoteEndPoint contains the default remote IP address and port number with which the Socket will communicate. You must cast this EndPoint to an IPEndPoint before retrieving any information. You can then call the IPEndPoint::Address method to retrieve the remote IPAddress, and the IPEndPoint::Port method to retrieve the remote port number.

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

System_CAPS_noteNote

This member outputs trace information when you enable network tracing in your application. For more information, see Network Tracing in the .NET Framework.

The following code example retrieves and displays the local and remote endpoints.

s->Connect( lep );

// Uses the RemoteEndPoint property.
Console::WriteLine(  "I am connected to {0} on port number {1}",
   IPAddress::Parse( ( ( (IPEndPoint^)(s->RemoteEndPoint) )->Address)->ToString() ),
   ( (IPEndPoint^)(s->RemoteEndPoint) )->Port.ToString() );

// Uses the LocalEndPoint property.
Console::Write(  "My local IpAddress is : {0}\nI am connected on port number {1}",
   IPAddress::Parse( ( ( (IPEndPoint^)(s->LocalEndPoint) )->Address)->ToString() ),
   ( (IPEndPoint^)(s->LocalEndPoint) )->Port.ToString() );

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Silverlight
Available since 2.0
Windows Phone Silverlight
Available since 7.1
Return to top
Show:
© 2016 Microsoft