IPEndPoint Class
Represents a network endpoint as an IP address and a port number.
The IPEndPoint class represents a network endpoint as an IP address and a port number. It is used by socket classes to establish connections and send/receive data. An IPEndPoint can represent either an IPv4 or an IPv6 endpoint.
When using the IPEndPoint(long) constructor, the Address property will be set to IPAddress.Any.
Constructors
-
public IPEndPoint(long rawAddress, int port)
Initializes a new instance of the
IPEndPointclass with the specified IP address and port number.rawAddress: A long integer that specifies the IP address.port: An int that specifies the port number.
-
public IPEndPoint(IPAddress address, int port)
Initializes a new instance of the
IPEndPointclass with the specified IP address and port number.address: An IPAddress instance.port: An int that specifies the port number.
Properties
-
public IPAddress Address { get; set; }
Gets or sets the IP address of the endpoint.
-
public int Port { get; set; }
Gets or sets the port number of the endpoint.
Methods
-
public override int Equals(object obj)
Determines whether two endpoint objects are equal.
-
public int Equals(IPEndPoint other)
Determines whether the current
IPEndPointrepresents the same network endpoint as anotherIPEndPoint. -
public override int GetHashCode()
Returns the hash code for the current
IPEndPoint. -
public void Parse(string endpoint)
Parses an IP address and port number from a string and stores them in the
IPEndPointinstance.endpoint: A string that contains the IP address and port number to parse. The string must be in the format "ipAddress:port" or "[IPv6Address]:port".
-
public override string ToString()
Converts an
IPEndPointto its string representation.// Example: IPEndPoint ipEndPoint = new IPEndPoint(IPAddress.Parse("192.168.1.1"), 8080); string ipEndPointString = ipEndPoint.ToString(); // ipEndPointString will be "192.168.1.1:8080"
Fields
-
public static readonly IPEndPoint Any
Represents an endpoint with the IP address
IPAddress.Anyand port 0.