SocketAddress クラス
アセンブリ: System (system.dll 内)
構文
解説
元になるバッファの最初の 2 バイトは、AddressFamily 列挙値用に予約されています。シリアル化した IPEndPoint の格納に SocketAddress を使用した場合、3 番目と 4 番目のバイトは、ポート番号情報の格納用に使用されます。後続のバイトは、IP アドレスを格納するために使用されます。バイト バッファは、0 から始まるインデックス番号を使用するため、このインデックス位置を参照して、基になるバイト バッファ内のすべての情報にアクセスできます。Family プロパティおよび Size プロパティを使用して、AddressFamily 値とバッファ サイズをそれぞれ取得することもできます。任意の情報を文字列として表示するには、ToString メソッドを使用します。
SocketAddress を使用して、EndPoint クラスのインスタンスをシリアル化する方法の例を次に示します。シリアル化が完了すると、SocketAddress の基になるバイト バッファには、すべての IPEndPoint ステータス情報が格納されます。
'Creates an IpEndPoint. Dim ipAddress As IPAddress = Dns.Resolve("www.contoso.com").AddressList(0) Dim ipLocalEndPoint As New IPEndPoint(ipAddress, 11000) 'Serializes the IPEndPoint. Dim socketAddress As SocketAddress = ipLocalEndPoint.Serialize() 'Verifies that ipLocalEndPoint is now serialized by printing its contents. Console.WriteLine(("Contents of socketAddress are: " + socketAddress.ToString())) 'Checks the Family property. Console.WriteLine(("The address family of socketAddress is: " + socketAddress.Family.ToString())) 'Checks the underlying buffer size. Console.WriteLine(("The size of the underlying buffer is: " + socketAddress.Size.ToString())) End Sub 'MySerializeIPEndPointClassMethod
//Creates an IpEndPoint. IPAddress ipAddress = Dns.Resolve("www.contoso.com").AddressList[0]; IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000); //Serializes the IPEndPoint. SocketAddress socketAddress = ipLocalEndPoint.Serialize(); //Verifies that ipLocalEndPoint is now serialized by printing its contents. Console.WriteLine("Contents of the socketAddress are: " + socketAddress.ToString()); //Checks the Family property. Console.WriteLine("The address family of the socketAddress is: " + socketAddress.Family.ToString()); //Checks the underlying buffer size. Console.WriteLine("The size of the underlying buffer is: " + socketAddress.Size.ToString());
//Creates an IpEndPoint. IPAddress^ ipAddress = Dns::Resolve( "www.contoso.com" )->AddressList[ 0 ]; IPEndPoint^ ipLocalEndPoint = gcnew IPEndPoint( ipAddress,11000 ); //Serializes the IPEndPoint. SocketAddress^ socketAddress = ipLocalEndPoint->Serialize(); //Verifies that ipLocalEndPoint is now serialized by printing its contents. Console::WriteLine( "Contents of the socketAddress are: {0}", socketAddress ); //Checks the Family property. Console::WriteLine( "The address family of the socketAddress is: {0}", socketAddress->Family ); //Checks the underlying buffer size. Console::WriteLine( "The size of the underlying buffer is: {0}", socketAddress->Size );
//Creates an IpEndPoint. IPAddress ipAddress = (IPAddress)Dns.Resolve( "www.contoso.com").get_AddressList().get_Item(0); IPEndPoint ipLocalEndPoint = new IPEndPoint(ipAddress, 11000); //Serializes the IPEndPoint. SocketAddress socketAddress = ipLocalEndPoint.Serialize(); //Verifies that ipLocalEndPoint is now serialized by printing its //contents. Console.WriteLine(("Contents of the socketAddress are: " + socketAddress.ToString())); //Checks the Family property. Console.WriteLine(("The address family of the socketAddress is: " + socketAddress.get_Family())); //Checks the underlying buffer size. Console.WriteLine(("The size of the underlying buffer is: " + socketAddress.get_Size()));
System.Net.SocketAddress
プラットフォーム
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。
参照
- SocketAddress クラスのページへのリンク