SocketAddress SocketAddress SocketAddress SocketAddress Class

Definizione

Archivia le informazioni serializzate dalla classi derivate EndPoint.Stores serialized information from EndPoint derived classes.

public ref class SocketAddress
public class SocketAddress
type SocketAddress = class
Public Class SocketAddress
Ereditarietà
SocketAddressSocketAddressSocketAddressSocketAddress

Esempi

Nell'esempio seguente viene illustrato come utilizzare SocketAddress per serializzare un'istanza EndPoint della classe.The following example demonstrates how to use SocketAddress to serialize an instance of the EndPoint class. Dopo la serializzazione, il buffer di byte SocketAddress sottostante di contiene tutte IPEndPoint le informazioni sullo stato.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
 

Commenti

I primi 2 byte del buffer sottostante sono riservati per il AddressFamily valore enumerato.The first 2 bytes of the underlying buffer are reserved for the AddressFamily enumerated value. Quando viene utilizzato per archiviare un oggetto IPEndPointserializzato, il terzo e il quarto byte vengono utilizzati per archiviare le informazioni sul numero di porta. SocketAddressWhen the SocketAddress is used to store a serialized IPEndPoint, the third and fourth bytes are used to store port number information. I byte successivi vengono usati per archiviare l'indirizzo IP.The next bytes are used to store the IP address. È possibile accedere a tutte le informazioni all'interno di questo buffer di byte sottostante facendo riferimento alla posizione di indice; il buffer di byte utilizza l'indicizzazione in base zero.You can access any information within this underlying byte buffer by referring to its index position; the byte buffer uses zero-based indexing. È anche possibile usare le Family proprietà Size e per ottenere rispettivamente AddressFamily il valore e le dimensioni del buffer.You can also use the Family and Size properties to get the AddressFamily value and the buffer size, respectively. Per visualizzare una qualsiasi di queste informazioni sotto forma di stringa, ToString utilizzare il metodo.To view any of this information as a string, use the ToString method.

Costruttori

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

Crea una nuova istanza della classe SocketAddress per la determinata famiglia di indirizzi.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)

Crea una nuova istanza della classe SocketAddress utilizzando la famiglia di indirizzi e la dimensione del buffer specificati.Creates a new instance of the SocketAddress class using the specified address family and buffer size.

Proprietà

Family Family Family Family

Recupera il valore enumerato di AddressFamily del SocketAddress corrente.Gets the AddressFamily enumerated value of the current SocketAddress.

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

Recupera o imposta l'elemento indice specificato nel buffer sottostante.Gets or sets the specified index element in the underlying buffer.

Size Size Size Size

Recupera la dimensione del buffer sottostante di SocketAddress.Gets the underlying buffer size of the SocketAddress.

Metodi

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

Determina se l'oggetto Object specificato è uguale all'oggetto Object corrente.Determines whether the specified Object is equal to the current Object.

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

Viene usato come funzione hash per un tipo particolare ed è adatto per l'uso in algoritmi di hash e in strutture dei dati come una tabella hash.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()

Ottiene l'oggetto Type dell'istanza corrente.Gets the Type of the current instance.

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

Crea una copia superficiale dell'oggetto Object corrente.Creates a shallow copy of the current Object.

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

Restituisce le informazioni sull'indirizzo socket.Returns information about the socket address.

Si applica a