SocketAddress クラス

定義

派生クラスからシリアル化された情報 EndPoint 格納します。

public ref class SocketAddress
public ref class SocketAddress : IEquatable<System::Net::SocketAddress ^>
public class SocketAddress
public class SocketAddress : IEquatable<System.Net.SocketAddress>
type SocketAddress = class
type SocketAddress = class
    interface IEquatable<SocketAddress>
Public Class SocketAddress
Public Class SocketAddress
Implements IEquatable(Of SocketAddress)
継承
SocketAddress
実装

次の例では、 SocketAddress を使用して、 EndPoint クラスのインスタンスをシリアル化する方法を示します。 シリアル化後、 SocketAddress の基になるバイト バッファーには、すべての IPEndPoint 状態情報が含まれます。


//Creates an IpEndPoint.
IPAddress ipAddress = Dns.GetHostEntry("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.
   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

注釈

基になるバッファーの最初の 2 バイトは、 AddressFamily 列挙値用に予約されています。 シリアル化されたSocketAddressを格納するためにIPEndPointを使用すると、3 番目と 4 番目のバイトがポート番号情報を格納するために使用されます。 次のバイトは、IP アドレスの格納に使用されます。 この基になるバイト バッファー内の任意の情報にアクセスするには、そのインデックス位置を参照します。バイト バッファーでは、0 から始まるインデックス作成が使用されます。 FamilyプロパティとSize プロパティを使用して、それぞれAddressFamily値とバッファー サイズを取得することもできます。 この情報を文字列として表示するには、 ToString メソッドを使用します。

コンストラクター

名前 説明
SocketAddress(AddressFamily, Int32)

指定したアドレス ファミリとバッファー サイズを使用して、 SocketAddress クラスの新しいインスタンスを作成します。

SocketAddress(AddressFamily)

指定したアドレス ファミリの SocketAddress クラスの新しいインスタンスを作成します。

プロパティ

名前 説明
Buffer

ネイティブ OS 呼び出しに渡すことができる基になるメモリを取得します。

Family

現在のAddressFamilySocketAddress列挙値を取得します。

Item[Int32]

基になるバッファー内の指定したインデックス要素を取得または設定します。

Size

SocketAddressの基になるバッファー サイズを取得します。

メソッド

名前 説明
Equals(Object)

指定した Object が現在の Objectと等しいかどうかを判断します。

Equals(SocketAddress)

現在のオブジェクトが同じ型の別のオブジェクトと等しいかどうかを示します。

GetHashCode()

ハッシュ アルゴリズムやハッシュ テーブルなどのデータ構造で使用するのに適した、特定の型のハッシュ関数として機能します。

GetMaximumAddressSize(AddressFamily)

指定された AddressFamilyに必要な最大バッファー サイズを取得します。

GetType()

現在のインスタンスの Type を取得します。

(継承元 Object)
MemberwiseClone()

現在の Objectの簡易コピーを作成します。

(継承元 Object)
ToString()

ソケット アドレスに関する情報を返します。

適用対象