Socket.RemoteEndPoint プロパティ

定義

リモート エンドポイントを取得します。

public:
 property System::Net::EndPoint ^ RemoteEndPoint { System::Net::EndPoint ^ get(); };
public System.Net.EndPoint RemoteEndPoint { get; }
public System.Net.EndPoint? RemoteEndPoint { get; }
member this.RemoteEndPoint : System.Net.EndPoint
Public ReadOnly Property RemoteEndPoint As EndPoint

プロパティ値

EndPointが通信しているSocket

例外

ソケットにアクセスしようとしたときにエラーが発生しました。

Socketが閉じられました。

次のコード例では、ローカル エンドポイントとリモート エンドポイントを取得して表示します。

s.Connect(lep);

// Using the RemoteEndPoint property.
Console.WriteLine("I am connected to " + IPAddress.Parse(((IPEndPoint)s.RemoteEndPoint).Address.ToString()) + "on port number " + ((IPEndPoint)s.RemoteEndPoint).Port.ToString());

// Using the LocalEndPoint property.
Console.WriteLine("My local IpAddress is :" + IPAddress.Parse(((IPEndPoint)s.LocalEndPoint).Address.ToString()) + "I am connected on port number " + ((IPEndPoint)s.LocalEndPoint).Port.ToString());
s.Connect(lep)

' Using the RemoteEndPoint property.
Console.WriteLine("I am connected to ")
Console.WriteLine(IPAddress.Parse(CType(s.RemoteEndPoint, IPEndPoint).Address.ToString()))
Console.WriteLine("on port number ")
Console.WriteLine(CType(s.RemoteEndPoint, IPEndPoint).Port.ToString())

' Using the LocalEndPoint property.
Console.WriteLine("My local IpAddress is :")
Console.WriteLine(IPAddress.Parse(CType(s.LocalEndPoint, IPEndPoint).Address.ToString()))
Console.WriteLine("I am connected on port number ")
Console.WriteLine(CType(s.LocalEndPoint, IPEndPoint).Port.ToString())

注釈

接続指向プロトコルを使用している場合、RemoteEndPoint プロパティは、EndPointが接続されているリモート IP アドレスとポート番号を含むSocketを取得します。 コネクションレス プロトコルを使用している場合、 RemoteEndPoint には、 Socket が通信する既定のリモート IP アドレスとポート番号が含まれます。 情報を取得する前に、この EndPointIPEndPoint にキャストする必要があります。 その後、 IPEndPoint.Address メソッドを呼び出してリモート IPAddressを取得し、 IPEndPoint.Port メソッドを呼び出してリモート ポート番号を取得できます。

RemoteEndPointは、AcceptまたはConnectへの呼び出し後に設定されます。 前にこのプロパティにアクセスしようとすると、 RemoteEndPointSocketExceptionをスローします。 SocketExceptionを受け取った場合は、SocketException.ErrorCode プロパティを使用して特定のエラー コードを取得します。 このコードを取得したら、エラーの詳細な説明については、 Windows ソケット バージョン 2 の API エラー コード のドキュメントを参照してください。

Note

このメンバーは、アプリケーションでネットワーク トレースを有効にすると、トレース情報を出力します。 詳細については、「Network Tracing in .NET Framework」を参照してください。

適用対象

こちらもご覧ください