IPEndPoint Konstruktoren

Definition

Initialisiert eine neue Instanz der IPEndPoint-Klasse.

Überlädt

Name Beschreibung
IPEndPoint(Int64, Int32)

Initialisiert eine neue Instanz der IPEndPoint Klasse mit der angegebenen Adresse und Portnummer.

IPEndPoint(IPAddress, Int32)

Initialisiert eine neue Instanz der IPEndPoint Klasse mit der angegebenen Adresse und Portnummer.

IPEndPoint(Int64, Int32)

Initialisiert eine neue Instanz der IPEndPoint Klasse mit der angegebenen Adresse und Portnummer.

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)

Parameter

address
Int64

Die IP-Adresse des Internethosts. Der Wert, der im Big-End-Format 0x2414188f wäre beispielsweise die IP-Adresse "143.24.20.36".

port
Int32

Die dem Port zugeordnete addressPortnummer oder 0, um einen beliebigen verfügbaren Port anzugeben. port ist in der Hostreihenfolge.

Ausnahmen

port ist kleiner als MinPort.

-oder-

port ist größer als MaxPort.

-oder-

address ist kleiner als 0 oder größer als 0x00000000FFFFFFFF.

Beispiele

Im folgenden Beispiel werden die angegebene IP-Adresse und die Portnummer verwendet, um eine IPEndPoint.


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()))

Gilt für:

IPEndPoint(IPAddress, Int32)

Initialisiert eine neue Instanz der IPEndPoint Klasse mit der angegebenen Adresse und Portnummer.

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)

Parameter

address
IPAddress

Ein IPAddress-Element.

port
Int32

Die dem Port zugeordnete addressPortnummer oder 0, um einen beliebigen verfügbaren Port anzugeben. port ist in der Hostreihenfolge.

Ausnahmen

address ist null.

port ist kleiner als MinPort.

-oder-

port ist größer als MaxPort.

Beispiele

// 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

Gilt für: