Export (0) Print
Expand All

IPEndPoint.Port Property

Gets or sets the TCP port number of the endpoint.

[Visual Basic]
Public Property Port As Integer
[C#]
public int Port {get; set;}
[C++]
public: __property int get_Port();
public: __property void set_Port(int);
[JScript]
public function get Port() : int;
public function set Port(int);

Property Value

An integer value in the range MinPort to MaxPort indicating the TCP port number of the endpoint.

Exceptions

Exception Type Condition
ArgumentOutOfRangeException The value that was specified for a set operation is less than MinPort or greater than MaxPort.

Example

[Visual Basic, C#, C++] The following example uses the Port property to set TCP port number of the EndPoint.

[Visual Basic] 
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 'displayEndpointInfo


[C#] 
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();
}

[C++] 
void displayEndpointInfo(IPEndPoint* endpoint)
{
   Console::WriteLine(S"Endpoint->Address : {0}", endpoint->Address);
   Console::WriteLine(S"Endpoint->AddressFamily : {0}", __box(endpoint->AddressFamily));
   Console::WriteLine(S"Endpoint->Port : {0}", __box(endpoint->Port));
   Console::WriteLine(S"Endpoint.ToString() : {0}", endpoint);

   Console::WriteLine(S"Press any key to continue.");
   Console::ReadLine();
}

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.

Requirements

Platforms: Windows 98, Windows NT 4.0, Windows Millennium Edition, Windows 2000, Windows XP Home Edition, Windows XP Professional, Windows Server 2003 family, .NET Compact Framework, Common Language Infrastructure (CLI) Standard

See Also

IPEndPoint Class | IPEndPoint Members | System.Net Namespace

Show:
© 2014 Microsoft