IPEndPoint.Port Property

Definition

Возвращает или задает номер порта конечной точки.Gets or sets the port number of the endpoint.

public:
 property int Port { int get(); void set(int value); };
public int Port { get; set; }
member this.Port : int with get, set
Public Property Port As Integer

Property Value

Int32

Целое значение из диапазона от MinPort до MaxPort, показывающее номер порта конечной точки.An integer value in the range MinPort to MaxPort indicating the port number of the endpoint.

Exceptions

Значение, заданное для установленной операции, меньше MinPort или больше MaxPort.The value that was specified for a set operation is less than MinPort or greater than MaxPort.

Examples

В следующем примере свойство Port используется для задания номера TCP-порта EndPoint.The following example uses the Port property to set TCP port number of the EndPoint.

void displayEndpointInfo( IPEndPoint^ endpoint )
{
   Console::WriteLine( "Endpoint->Address : {0}", endpoint->Address );
   Console::WriteLine( "Endpoint->AddressFamily : {0}", endpoint->AddressFamily );
   Console::WriteLine( "Endpoint->Port : {0}", endpoint->Port );
   Console::WriteLine( "Endpoint.ToString() : {0}", endpoint );
   Console::WriteLine( "Press any key to continue." );
   Console::ReadLine();
}
private static void displayEndpointInfo(IPEndPoint endpoint)
{
  Console.WriteLine("Endpoint.Address : " + endpoint.Address);
  Console.WriteLine("Endpoint.AddressFamily : " + endpoint.AddressFamily);
  Console.WriteLine("Endpoint.Port : " + endpoint.Port);
  Console.WriteLine("Endpoint.ToString() : " + endpoint.ToString());

  Console.WriteLine("Press any key to continue.");
  Console.ReadLine();
}
Private Shared Sub displayEndpointInfo(ByVal endpoint As IPEndPoint)
  Console.WriteLine("Endpoint Address : " + endpoint.Address.ToString())
  Console.WriteLine("Endpoint AddressFamily : " + endpoint.AddressFamily.ToString())
  Console.WriteLine("Endpoint Port : " + endpoint.Port.ToString())
  Console.WriteLine("Endpoint ToString() : " + endpoint.ToString())

  Console.WriteLine("Press any key to continue.")
  Console.ReadLine()
End Sub

Applies to