Läs på engelska Redigera

Dela via


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.

C#
public IPEndPoint(long address, int port);

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.

C#

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

Applies to

.NET 10 och andra versioner
Produkt Versioner
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0

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.

C#
public IPEndPoint(System.Net.IPAddress address, int port);

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

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;
            }
        }

Applies to

.NET 10 och andra versioner
Produkt Versioner
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1
UWP 10.0