Export (0) Print
Expand All

IPEndPoint Constructor (IPAddress, Int32)

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
)

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 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 .NET Framework does not support all versions of every platform. For a list of the supported versions, see System Requirements.

.NET Framework

Supported in: 2.0, 1.1, 1.0

.NET Compact Framework

Supported in: 2.0, 1.0

Community Additions

ADD
Show:
© 2014 Microsoft