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::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 = 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.
   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 時,會使用第三個和第四個位元組來儲存埠號碼資訊。 下一個位元組是用來儲存 IP 位址。 您可以參考其索引位置,來存取此基礎位元組緩衝區內的任何資訊;位元組緩衝區使用以零起始的索引。 您也可以分別使用 FamilySize 屬性來取得 AddressFamily 值和緩衝區大小。 若要以字串的形式檢視任何這項資訊,請使用 ToString 方法。

建構函式

SocketAddress(AddressFamily)

為指定的通訊協定家族 (Address Family) 建立 SocketAddress 類別的新執行個體。

SocketAddress(AddressFamily, Int32)

使用指定的通訊協定家族和緩衝區大小來初始化 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()

傳回通訊端 (Socket) 位址的相關資訊。

適用於