SocketAddress Classe

Definição

Armazena informações serializadas de classes derivadas de EndPoint.Stores serialized information from EndPoint derived classes.

public ref class SocketAddress
public class SocketAddress
type SocketAddress = class
Public Class SocketAddress
Herança
SocketAddress

Exemplos

O exemplo a seguir demonstra como usar o SocketAddress para serializar uma instância da EndPoint classe.The following example demonstrates how to use SocketAddress to serialize an instance of the EndPoint class. Após a serialização, o buffer de bytes subjacente do SocketAddress contém todas as IPEndPoint informações de estado.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
 

Comentários

Os primeiros 2 bytes do buffer subjacente são reservados para o AddressFamily valor enumerado.The first 2 bytes of the underlying buffer are reserved for the AddressFamily enumerated value. Quando o SocketAddress é usado para armazenar um serializado IPEndPoint , o terceiro e o quarto bytes são usados para armazenar informações de número da porta.When the SocketAddress is used to store a serialized IPEndPoint, the third and fourth bytes are used to store port number information. Os próximos bytes são usados para armazenar o endereço IP.The next bytes are used to store the IP address. Você pode acessar qualquer informação dentro desse buffer de bytes subjacente, referindo-se à sua posição de índice; o buffer de bytes usa a indexação baseada em zero.You can access any information within this underlying byte buffer by referring to its index position; the byte buffer uses zero-based indexing. Você também pode usar as Family Size Propriedades e para obter o AddressFamily valor e o tamanho do buffer, respectivamente.You can also use the Family and Size properties to get the AddressFamily value and the buffer size, respectively. Para exibir qualquer uma dessas informações como uma cadeia de caracteres, use o ToString método.To view any of this information as a string, use the ToString method.

Construtores

SocketAddress(AddressFamily)

Cria uma nova instância da classe SocketAddress para a família de endereços determinada.Creates a new instance of the SocketAddress class for the given address family.

SocketAddress(AddressFamily, Int32)

Cria uma nova instância da classe SocketAddress usando a família de endereços especificada e o tamanho do buffer.Creates a new instance of the SocketAddress class using the specified address family and buffer size.

Propriedades

Family

Obtém o valor enumerado AddressFamily do SocketAddress atual.Gets the AddressFamily enumerated value of the current SocketAddress.

Item[Int32]

Obtém ou define o elemento de índice especificado no buffer subjacente.Gets or sets the specified index element in the underlying buffer.

Size

Obtém o tamanho do buffer subjacente do SocketAddress.Gets the underlying buffer size of the SocketAddress.

Métodos

Equals(Object)

Determina se o Object especificado é igual ao Object atual.Determines whether the specified Object is equal to the current Object.

GetHashCode()

Atua como uma função de hash para um tipo específico, adequada para uso em algoritmos de hash e estruturas de dados como uma tabela de hash.Serves as a hash function for a particular type, suitable for use in hashing algorithms and data structures like a hash table.

GetType()

Obtém o Type da instância atual.Gets the Type of the current instance.

(Herdado de Object)
MemberwiseClone()

Cria uma cópia superficial do Object atual.Creates a shallow copy of the current Object.

(Herdado de Object)
ToString()

Retorna informações sobre o endereço do soquete.Returns information about the socket address.

Aplica-se a