This documentation is archived and is not being maintained.

IPEndPoint Constructor (IPAddress, Int32)

.NET Framework 1.1

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

[Visual Basic]
Public Sub New( _
   ByVal address As IPAddress, _
   ByVal port As Integer _
)
[C#]
public IPEndPoint(
   IPAddress address,
 int port
);
[C++]
public: IPEndPoint(
   IPAddress* address,
 int port
);
[JScript]
public function IPEndPoint(
   address : IPAddress,
 port : int
);

Parameters

address
An IPAddress.
port
The port number associated with address.

Exceptions

Exception Type Condition
ArgumentOutOfRangeException port is less than MinPort.

-or-

port is greater than MaxPort.

-or-

address is less than 0 or greater than 0x00000000FFFFFFFF.

Example

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


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

[C++] 
// Obtain the IP address from the list of IP addresses associated with the server.
System::Collections::IEnumerator* myEnum = host->AddressList->GetEnumerator();
while (myEnum->MoveNext())
{
   IPAddress* address = __try_cast<IPAddress*>(myEnum->Current);
   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;
}

[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 | IPEndPoint Constructor Overload List

Show: