Freigeben über


SocketAddress-Klasse

Speichert serialisierte Informationen von Klassen, die von EndPoint abgeleitet sind.

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

Syntax

'Declaration
Public Class SocketAddress
'Usage
Dim instance As SocketAddress
public class SocketAddress
public ref class SocketAddress
public class SocketAddress
public class SocketAddress

Hinweise

Die ersten 2 Bytes des zugrunde liegenden Puffers sind für den AddressFamily-Enumerationswert reserviert. Wenn der SocketAddress zum Speichern eines serialisierten IPEndPoint verwendet wird, werden das dritte und vierte Byte zum Speichern von Anschlussnummerinformationen verwendet. Die nächsten Bytes werden zum Speichern der IP-Adresse verwendet. Sie können auf die Informationen in diesem zugrunde liegenden Bytepuffer über die entsprechenden Indexpositionen zugreifen. Für den Bytepuffer wird eine nullbasierte Indizierung verwendet. Außerdem haben Sie die Möglichkeit, über die Family-Eigenschaft und die Size-Eigenschaft den AddressFamily-Wert bzw. die Puffergröße abzurufen. Verwenden Sie die ToString-Methode, wenn Sie diese Informationen als Zeichenfolgen anzeigen möchten.

Beispiel

Im folgenden Beispiel wird veranschaulicht, wie mit SocketAddress eine Instanz der EndPoint-Klasse serialisiert werden kann. Nach dem Serialisieren enthält der zugrunde liegende Bytepuffer der SocketAddress alle IPEndPoint-Zustandsinformationen.

   '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()));

Vererbungshierarchie

System.Object
  System.Net.SocketAddress

Threadsicherheit

Alle öffentlichen statischen (Shared in Visual Basic) Member dieses Typs sind threadsicher. Bei Instanzmembern ist die Threadsicherheit nicht gewährleistet.

Plattformen

Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile für Pocket PC, Windows Mobile für Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

.NET Framework unterstützt nicht alle Versionen sämtlicher Plattformen. Eine Liste der unterstützten Versionen finden Sie unter Systemanforderungen.

Versionsinformationen

.NET Framework

Unterstützt in: 2.0, 1.1, 1.0

.NET Compact Framework

Unterstützt in: 2.0, 1.0

Siehe auch

Referenz

SocketAddress-Member
System.Net-Namespace