Breyta

Deila með


IPEndPoint Constructors

Definition

Initializes a new instance of the IPEndPoint class.

Overloads

IPEndPoint(Int64, Int32)

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

IPEndPoint(IPAddress, Int32)

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

IPEndPoint(Int64, Int32)

Source:
IPEndPoint.cs
Source:
IPEndPoint.cs
Source:
IPEndPoint.cs

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

public:
 IPEndPoint(long address, int port);
public IPEndPoint (long address, int port);
new System.Net.IPEndPoint : int64 * int -> System.Net.IPEndPoint
Public Sub New (address As Long, port As Integer)

Parameters

address
Int64

The IP address of the Internet host. For example, the value 0x2414188f in big-endian format would be the IP address "143.24.20.36".

port
Int32

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

Exceptions

port is less than MinPort.

-or-

port is greater than MaxPort.

-or-

address is less than 0 or greater than 0x00000000FFFFFFFF.

Examples

The following example uses the specified IP address and port number to create an IPEndPoint.

IPAddress^ hostIPAddress1 = (Dns::Resolve( hostString1 ))->AddressList[ 0 ];
Console::WriteLine( hostIPAddress1 );
IPEndPoint^ hostIPEndPoint = gcnew IPEndPoint( hostIPAddress1,80 );
Console::WriteLine( "\nIPEndPoint information:{0}", hostIPEndPoint );
Console::WriteLine( "\n\tMaximum allowed Port Address :{0}", IPEndPoint::MaxPort );
Console::WriteLine( "\n\tMinimum allowed Port Address :{0}", (int^)IPEndPoint::MinPort );
Console::WriteLine( "\n\tAddress Family :{0}", hostIPEndPoint->AddressFamily );

IPAddress hostIPAddress1 = (Dns.Resolve(hostString1)).AddressList[0];
Console.WriteLine(hostIPAddress1.ToString());
IPEndPoint hostIPEndPoint = new IPEndPoint(hostIPAddress1,80);
Console.WriteLine("\nIPEndPoint information:" + hostIPEndPoint.ToString());
Console.WriteLine("\n\tMaximum allowed Port Address :" + IPEndPoint.MaxPort);
Console.WriteLine("\n\tMinimum allowed Port Address :" + IPEndPoint.MinPort);
Console.WriteLine("\n\tAddress Family :" + hostIPEndPoint.AddressFamily);
Dim hostIPAddress1 As IPAddress = Dns.Resolve(hostString1).AddressList(0)
Dim hostIPEndPoint As New IPEndPoint(hostIPAddress1, 80)
Console.WriteLine((ControlChars.Cr + "IPEndPoint information:" + hostIPEndPoint.ToString()))
Console.WriteLine((ControlChars.Cr + ControlChars.Tab + "Maximum allowed Port Address :" + IPEndPoint.MaxPort.ToString()))
Console.WriteLine((ControlChars.Cr + ControlChars.Tab + "Minimum allowed Port Address :" + IPEndPoint.MinPort.ToString()))
Console.WriteLine((ControlChars.Cr + ControlChars.Tab + "Address Family :" + hostIPEndPoint.AddressFamily.ToString()))

Applies to

IPEndPoint(IPAddress, Int32)

Source:
IPEndPoint.cs
Source:
IPEndPoint.cs
Source:
IPEndPoint.cs

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

public:
 IPEndPoint(System::Net::IPAddress ^ address, int port);
public IPEndPoint (System.Net.IPAddress address, int port);
new System.Net.IPEndPoint : System.Net.IPAddress * int -> System.Net.IPEndPoint
Public Sub New (address As IPAddress, port As Integer)

Parameters

address
IPAddress

An IPAddress.

port
Int32

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

Exceptions

address is null.

port is less than MinPort.

-or-

port is greater than MaxPort.

Examples

// 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 = safe_cast<IPAddress^>(myEnum->Current);
   IPEndPoint^ endpoint = gcnew IPEndPoint( address,port );
   tempSocket = gcnew 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.
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.
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

Applies to