IPEndPoint Construtores
Definição
Importante
Algumas informações se referem a produtos de pré-lançamento que podem ser substancialmente modificados antes do lançamento. A Microsoft não oferece garantias, expressas ou implícitas, das informações aqui fornecidas.
Inicializa uma nova instância da classe IPEndPoint.
Sobrecargas
| Nome | Description |
|---|---|
| IPEndPoint(Int64, Int32) |
Inicializa uma nova instância da IPEndPoint classe com o endereço e o número da porta especificados. |
| IPEndPoint(IPAddress, Int32) |
Inicializa uma nova instância da IPEndPoint classe com o endereço e o número da porta especificados. |
IPEndPoint(Int64, Int32)
Inicializa uma nova instância da IPEndPoint classe com o endereço e o número da porta especificados.
public:
IPEndPoint(long address, int port);
public IPEndPoint(long address, int port);
new System.Net.IPEndPoint : int64 * int -> System.Net.IPEndPoint
Public Sub New (address As Long, port As Integer)
Parâmetros
- address
- Int64
O endereço IP do host da Internet. Por exemplo, o valor 0x2414188f no formato big-endian seria o endereço IP "143.24.20.36".
- port
- Int32
O número da porta associado ao address, ou 0, para especificar qualquer porta disponível.
port está em ordem de host.
Exceções
port é menor que MinPort.
-ou-
port é maior que MaxPort.
-ou-
address é menor que 0 ou maior que 0x00000000FFFFFFFF.
Exemplos
O exemplo a seguir usa o endereço IP especificado e o número da porta para criar um IPEndPoint.
IPAddress hostIPAddress1 = (Dns.Resolve(hostString1)).AddressList[0];
Console.WriteLine(hostIPAddress1.ToString());
IPEndPoint hostIPEndPoint = new IPEndPoint(hostIPAddress1,80);
Console.WriteLine("\nIPEndPoint information:" + hostIPEndPoint.ToString());
Console.WriteLine("\n\tMaximum allowed Port Address :" + IPEndPoint.MaxPort);
Console.WriteLine("\n\tMinimum allowed Port Address :" + IPEndPoint.MinPort);
Console.WriteLine("\n\tAddress Family :" + hostIPEndPoint.AddressFamily);
Dim hostIPAddress1 As IPAddress = Dns.Resolve(hostString1).AddressList(0)
Dim hostIPEndPoint As New IPEndPoint(hostIPAddress1, 80)
Console.WriteLine((ControlChars.Cr + "IPEndPoint information:" + hostIPEndPoint.ToString()))
Console.WriteLine((ControlChars.Cr + ControlChars.Tab + "Maximum allowed Port Address :" + IPEndPoint.MaxPort.ToString()))
Console.WriteLine((ControlChars.Cr + ControlChars.Tab + "Minimum allowed Port Address :" + IPEndPoint.MinPort.ToString()))
Console.WriteLine((ControlChars.Cr + ControlChars.Tab + "Address Family :" + hostIPEndPoint.AddressFamily.ToString()))
Aplica-se a
IPEndPoint(IPAddress, Int32)
Inicializa uma nova instância da IPEndPoint classe com o endereço e o número da porta especificados.
public:
IPEndPoint(System::Net::IPAddress ^ address, int port);
public IPEndPoint(System.Net.IPAddress address, int port);
new System.Net.IPEndPoint : System.Net.IPAddress * int -> System.Net.IPEndPoint
Public Sub New (address As IPAddress, port As Integer)
Parâmetros
- port
- Int32
O número da porta associado ao address, ou 0, para especificar qualquer porta disponível.
port está em ordem de host.
Exceções
address é null.
Exemplos
// Obtain the IP address from the list of IP addresses associated with the server.
foreach(IPAddress address in host.AddressList)
{
IPEndPoint endpoint = new IPEndPoint(address, port);
tempSocket =
new Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp);
tempSocket.Connect(endpoint);
if(tempSocket.Connected)
{
// Display the endpoint information.
displayEndpointInfo(endpoint);
// Serialize the endpoint to obtain a SocketAddress object.
serializedSocketAddress = serializeEndpoint(endpoint);
break;
}
else
{
continue;
}
}
' Obtain the IP address from the list of IP addresses associated with the server.
Dim address As IPAddress
For Each address In host.AddressList
Dim endpoint As New IPEndPoint(address, port)
tempSocket = New Socket(endpoint.AddressFamily, SocketType.Stream, ProtocolType.Tcp)
tempSocket.Connect(endpoint)
If tempSocket.Connected Then
' Display the endpoint information.
displayEndpointInfo(endpoint)
' Serialize the endpoint to obtain a SocketAddress object.
serializedSocketAddress = serializeEndpoint(endpoint)
Exit For
End If
Next address