is new.
java.lang.Objectjava.net.SocketAddress
java.net.InetSocketAddress
This class implements an IP Socket Address (IP address + port number) It can also be a pair (hostname + port number), in which case an attempt will be made to resolve the hostname. If resolution fails then the address is said to be unresolved but can still be used on some circumstances like connecting through a proxy.
It provides an immutable object used by sockets for binding, connecting, or as returned values.
The wildcard is a special local IP address. It usually means "any" and can only be used for bind operations.
| Constructor Summary | |
|---|---|
|
InetSocketAddress
(
InetAddress
addr, int port) Creates a socket address from an IP address and a port number. |
|
|
InetSocketAddress
(int port) Creates a socket address where the IP address is the wildcard address and the port number a specified value. |
|
|
InetSocketAddress
(
String
hostname, int port) Creates a socket address from a hostname and a port number. |
|
| Method Summary | |
|---|---|
static
InetSocketAddress
|
createUnresolved
(
String
Creates an unresolved socket address from a hostname and a port number.
|
| boolean |
equals
(
Object
obj) Compares this object against the specified object. |
| InetAddress |
getAddress
() Gets the InetAddress. |
| String |
getHostName
() Gets the hostname. |
| int |
getPort
() Gets the port number. |
| int |
hashCode
() Returns a hashcode for this socket address. |
| boolean |
isUnresolved
() Checks
whether
|
| String |
toString
() Constructs a string representation of this InetSocketAddress. |
| Methods inherited from class java.lang. Object |
|---|
| clone , finalize , getClass , notify , notifyAll , wait , wait , wait |
| Constructor Detail |
|---|
public InetSocketAddress(int port)
A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.
public InetSocketAddress(InetAddress addr,
int port)
A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.
A null address will assign the wildcard address.
public InetSocketAddress(String hostname,
int port)
An attempt will be made to resolve the hostname into an InetAddress. If that attempt fails, the address will be flagged as unresolved .
If there is a security manager, its checkConnect method is called with the host name as its argument to check the permissiom to resolve it. This could result in a SecurityException.
A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.
SecurityException
- if a security manager is present and permission to resolve the host name is denied.
| Method Detail |
|---|
createUnresolved
public static
InetSocketAddress
createUnresolved
(
String
host, int port)
Creates an unresolved socket address from a hostname and a port number.
No attempt will be made to resolve the hostname into an InetAddress. The address will be flagged as
unresolved
.
A valid port value is between 0 and 65535. A port number of zero will let the system pick up an ephemeral port in a bind operation.
Parameters:
hostname - the Host name
port - The port number
Throws:
IllegalArgumentException
- if the port parameter is outside the range of valid port values, or if the hostname parameter is
null
.
Since:
1.5
See Also:
isUnresolved()
public final int getPort()
public final InetAddress getAddress()
public final String getHostName()
public final boolean isUnresolved()
whether
public String toString()
public final boolean equals(Object obj)
Two instances of InetSocketAddress represent the same address if both the InetAddresses (or hostnames if it is unresolved) and port numbers are equal. If both addresses are unresolved, then the hostname & the port number are compared.
public final int hashCode()