SocketAddress SocketAddress SocketAddress SocketAddress Class

Définition

Stocke des informations sérialisées provenant des classes dérivées EndPoint.Stores serialized information from EndPoint derived classes.

public ref class SocketAddress
public class SocketAddress
type SocketAddress = class
Public Class SocketAddress
Héritage
SocketAddressSocketAddressSocketAddressSocketAddress

Exemples

L’exemple suivant montre comment utiliser SocketAddress pour sérialiser une instance de la EndPoint classe.The following example demonstrates how to use SocketAddress to serialize an instance of the EndPoint class. Après la sérialisation, la mémoire tampon d’octets sous-jacente de la SocketAddress contient tous les IPEndPoint des informations d’état.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 'MySerializeIPEndPointClassMethod
 

Remarques

Les 2 premiers octets de la mémoire tampon sous-jacente sont réservés pour le AddressFamily valeur énumérée.The first 2 bytes of the underlying buffer are reserved for the AddressFamily enumerated value. Lorsque le SocketAddress est utilisé pour stocker un sérialisée IPEndPoint, les troisième et quatrième octets sont utilisés pour stocker les informations de numéro de port.When the SocketAddress is used to store a serialized IPEndPoint, the third and fourth bytes are used to store port number information. Les octets sont utilisés pour stocker l’adresse IP.The next bytes are used to store the IP address. Vous pouvez accéder à toutes les informations au sein de cette mémoire tampon d’octets sous-jacente en faisant référence à sa position d’index ; la mémoire tampon d’octets utilise une indexation de base zéro.You can access any information within this underlying byte buffer by referring to its index position; the byte buffer uses zero-based indexing. Vous pouvez également utiliser le Family et Size propriétés permettant d’obtenir le AddressFamily valeur et la mémoire tampon de taille, respectivement.You can also use the Family and Size properties to get the AddressFamily value and the buffer size, respectively. Pour afficher ces informations sous forme de chaîne, utilisez la ToString (méthode).To view any of this information as a string, use the ToString method.

Constructeurs

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

Crée une instance de la classe SocketAddress pour la famille d'adresses donnée.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)

Crée une nouvelle instance de la classe SocketAddress en utilisant la famille d'adresses et la taille de mémoire tampon spécifiées.Creates a new instance of the SocketAddress class using the specified address family and buffer size.

Propriétés

Family Family Family Family

Obtient la valeur énumérée AddressFamily du SocketAddress actuel.Gets the AddressFamily enumerated value of the current SocketAddress.

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

Obtient ou définit l'élément d'index spécifié dans la mémoire tampon sous-jacente.Gets or sets the specified index element in the underlying buffer.

Size Size Size Size

Obtient la taille de la mémoire tampon sous-jacente de SocketAddress.Gets the underlying buffer size of the SocketAddress.

Méthodes

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

Détermine si l'objet Object spécifié est égal à l'objet Object actuel.Determines whether the specified Object is equal to the current Object.

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

Sert de fonction de hachage pour un type particulier et convient à une utilisation dans des algorithmes de hachage et des structures de données telles qu’une table de hachage.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()

Obtient le Type de l'instance actuelle.Gets the Type of the current instance.

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

Crée une copie superficielle du Object actuel.Creates a shallow copy of the current Object.

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

Retourne des informations sur l'adresse du socket.Returns information about the socket address.

S’applique à