SocketAddress SocketAddress SocketAddress SocketAddress Class

Definition

Speichert serialisierte Informationen von Klassen, die von EndPoint abgeleitet sind.Stores serialized information from EndPoint derived classes.

public ref class SocketAddress
public class SocketAddress
type SocketAddress = class
Public Class SocketAddress
Vererbung
SocketAddressSocketAddressSocketAddressSocketAddress

Beispiele

Im folgenden Beispiel wird veranschaulicht, wie SocketAddress verwendet wird, um eine Instanz EndPoint der-Klasse zu serialisieren.The following example demonstrates how to use SocketAddress to serialize an instance of the EndPoint class. Nach der Serialisierung SocketAddress enthält der zugrunde liegende Byte Puffer von alle IPEndPoint Zustandsinformationen.After serialization, the underlying byte buffer of the SocketAddress contains all of the IPEndPoint state information.

//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
 

Hinweise

Die ersten 2 Bytes des zugrunde liegenden Puffers sind für den AddressFamily -Enumerationswert reserviert.The first 2 bytes of the underlying buffer are reserved for the AddressFamily enumerated value. Wenn das SocketAddress zum Speichern eines serialisierten IPEndPointverwendet wird, werden das dritte und vierte Byte zum Speichern von Informationen zu Portnummern verwendet.When the SocketAddress is used to store a serialized IPEndPoint, the third and fourth bytes are used to store port number information. Die nächsten Bytes werden zum Speichern der IP-Adresse verwendet.The next bytes are used to store the IP address. Sie können auf alle Informationen innerhalb dieses zugrunde liegenden Byte Puffers zugreifen, indem Sie auf die Indexposition verweisen. der Byte Puffer verwendet die null basierte Indizierung.You can access any information within this underlying byte buffer by referring to its index position; the byte buffer uses zero-based indexing. Sie können auch die Family und Size Eigenschaften zum Abrufen der AddressFamily Wert und der Puffer die Größe, bzw.You can also use the Family and Size properties to get the AddressFamily value and the buffer size, respectively. Um diese Informationen als Zeichenfolge anzuzeigen, verwenden Sie die ToString -Methode.To view any of this information as a string, use the ToString method.

Konstruktoren

SocketAddress(AddressFamily) SocketAddress(AddressFamily) SocketAddress(AddressFamily) SocketAddress(AddressFamily)

Erstellt eine neue Instanz der SocketAddress-Klasse für die angegebene Adressfamilie.Creates a new instance of the SocketAddress class for the given address family.

SocketAddress(AddressFamily, Int32) SocketAddress(AddressFamily, Int32) SocketAddress(AddressFamily, Int32) SocketAddress(AddressFamily, Int32)

Erstellt eine neue Instanz der SocketAddress-Klasse, wobei die angegebene Adressfamilie und die angegebene Puffergröße verwendet werden.Creates a new instance of the SocketAddress class using the specified address family and buffer size.

Eigenschaften

Family Family Family Family

Ruft den AddressFamily-Enumerationswert der aktuellen SocketAddress ab.Gets the AddressFamily enumerated value of the current SocketAddress.

Item[Int32] Item[Int32] Item[Int32] Item[Int32]

Ruft das angegebene Indexelement im zugrunde liegenden Puffer ab oder legt dieses fest.Gets or sets the specified index element in the underlying buffer.

Size Size Size Size

Ruft die Größe des zugrunde liegenden Puffers der SocketAddress ab.Gets the underlying buffer size of the SocketAddress.

Methoden

Equals(Object) Equals(Object) Equals(Object) Equals(Object)

Bestimmt, ob das angegebene Object und das aktuelle Object gleich sind.Determines whether the specified Object is equal to the current Object.

GetHashCode() GetHashCode() GetHashCode() GetHashCode()

Fungiert als Hashfunktion für einen bestimmten Typ, der sich für die Verwendung in Hashalgorithmen und Datenstrukturen eignet, z. B. einer Hashtabelle.Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.

GetType() GetType() GetType() GetType()

Ruft den Type der aktuellen Instanz ab.Gets the Type of the current instance.

(Inherited from Object)
MemberwiseClone() MemberwiseClone() MemberwiseClone() MemberwiseClone()

Erstellt eine flache Kopie des aktuellen Object.Creates a shallow copy of the current Object.

(Inherited from Object)
ToString() ToString() ToString() ToString()

Gibt Informationen über die Socketadresse zurück.Returns information about the socket address.

Gilt für: