Export (0) Print
Expand All

IPEndPoint.IPEndPoint(IPAddress, Int32) Constructor

Initializes a new instance of the IPEndPoint class with the specified address and port number.

Namespace: System.Net
Assembly: System (in system.dll)

public IPEndPoint (
	IPAddress address,
	int port
)
public IPEndPoint (
	IPAddress address, 
	int port
)
public function IPEndPoint (
	address : IPAddress, 
	port : int
)
Not applicable.

Parameters

address

An IPAddress.

port

The port number associated with the address, or 0 to specify any available port. port is in host order.

Exception typeCondition

ArgumentOutOfRangeException

port is less than MinPort.

-or-

port is greater than MaxPort.

-or-

address is less than 0 or greater than 0x00000000FFFFFFFF.

// 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.
for (int iCtr = 0; iCtr < host.get_AddressList().length; iCtr++) {
    IPAddress address = host.get_AddressList()[iCtr];
    IPEndPoint endpoint = new IPEndPoint(address, port);
    tempSocket = new Socket(endpoint.get_AddressFamily(), 
        SocketType.Stream, ProtocolType.Tcp);
    tempSocket.Connect(endpoint);
    if (tempSocket.get_Connected()) {
        // Display the endpoint information.
        DisplayEndpointInfo(endpoint);
        // Serialize the endpoint to obtain a SocketAddress object.
        serializedSocketAddress = SerializeEndpoint(endpoint);
        break;    
    }
    else {
        continue;
    }
}

Windows 98, Windows Server 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition

The Microsoft .NET Framework 3.0 is supported on Windows Vista, Microsoft Windows XP SP2, and Windows Server 2003 SP1.

.NET Framework

Supported in: 3.0, 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft