public class InetSocketAddress extends SocketAddress
SocketAddress for IP.| Constructor and Description |
|---|
InetSocketAddress() |
InetSocketAddress(InetAddress address,
int port)
Creates a socket endpoint with the given port number
port and
address. |
InetSocketAddress(int port)
Creates a socket endpoint with the given port number
port and
no specified address. |
InetSocketAddress(String host,
int port)
Creates a socket endpoint with the given port number
port and the
hostname host. |
| Modifier and Type | Method and Description |
|---|---|
static InetSocketAddress |
createUnresolved(String host,
int port)
Creates an
InetSocketAddress without trying to resolve the
hostname into an InetAddress. |
boolean |
equals(Object socketAddr)
Compares two socket endpoints and returns true if they are equal.
|
InetAddress |
getAddress()
Returns the socket endpoint's address.
|
String |
getHostName()
Returns the hostname, doing a reverse DNS lookup on the
InetAddress if no
hostname string was provided at construction time. |
String |
getHostString()
Returns the hostname if known, or the result of
InetAddress.getHostAddress. |
int |
getPort()
Returns the socket endpoint's port.
|
int |
hashCode()
Returns an integer hash code for this object.
|
boolean |
isUnresolved()
Returns whether this socket address is unresolved or not.
|
String |
toString()
Returns a string containing the address (or the hostname for an
unresolved
InetSocketAddress) and port number. |
public InetSocketAddress()
public InetSocketAddress(int port)
port and
no specified address. The range for valid port numbers is between 0 and
65535 inclusive.port - the port number of the socket endpoint.public InetSocketAddress(InetAddress address, int port)
port and
address. The range for valid port numbers is between 0 and 65535
inclusive. If address is null the address is set to a
wildcard address.address - the address of the socket endpoint.port - the port number of the socket endpoint.public InetSocketAddress(String host, int port)
port and the
hostname host. The hostname is tried to be resolved and cannot be
null. The range for valid port numbers is between 0 and 65535
inclusive.host - the hostname of the socket endpoint.port - the port number of the socket endpoint.public static InetSocketAddress createUnresolved(String host, int port)
InetSocketAddress without trying to resolve the
hostname into an InetAddress. The address field is marked as
unresolved.host - the hostname of the socket endpoint.port - the port number of the socket endpoint.IllegalArgumentException - if the hostname host is null or the port is
not in the range between 0 and 65535.public final int getPort()
public final InetAddress getAddress()
public final String getHostName()
InetAddress if no
hostname string was provided at construction time. Use getHostString() to
avoid the reverse DNS lookup.public final String getHostString()
InetAddress.getHostAddress.
Unlike getHostName(), this method will never cause a DNS lookup.public final boolean isUnresolved()
true if this socket address is unresolved, false
otherwise.public String toString()
InetSocketAddress) and port number.
For example: "www.google.com/74.125.224.115:80" or "/127.0.0.1:80".public final boolean equals(Object socketAddr)
equals in class ObjectsocketAddr - the object to be tested for equality.true if this socket endpoint and the given socket endpoint socketAddr are equal, false otherwise.Object.hashCode()public final int hashCode()
ObjectObject.equals(java.lang.Object) returns true must return
the same hash code value. This means that subclasses of Object
usually override both methods or neither method.
Note that hash values must not change over time unless information used in equals comparisons also changes.
See Writing a correct
hashCode method
if you intend implementing your own hashCode method.
hashCode in class ObjectObject.equals(java.lang.Object)