Constructors Summary |
---|
public InetSocketAddress(int port)Creates a socket endpoint with the given port number {@code port} and the
wildcard address {@code InetAddress.ANY}. The range for valid port numbers
is between 0 and 65535 inclusive.
this((InetAddress) null, port);
|
public InetSocketAddress(InetAddress address, int port)Creates a socket endpoint with the given port number {@code port} and
{@code address}. The range for valid port numbers is between 0 and 65535
inclusive. If {@code address} is {@code null} this socket is bound to the
wildcard address {@code InetAddress.ANY}.
if (port < 0 || port > 65535) {
throw new IllegalArgumentException();
}
if (address == null) {
addr = InetAddress.ANY;
} else {
addr = address;
}
hostname = addr.getHostName();
this.port = port;
|
public InetSocketAddress(String host, int port)Creates a socket endpoint with the given port number {@code port} and the
hostname {@code host}. The hostname is tried to be resolved and cannot be
{@code null}. The range for valid port numbers is between 0 and 65535
inclusive.
this(host, port, true);
|
InetSocketAddress(String host, int port, boolean needResolved)
if (host == null || port < 0 || port > 65535) {
throw new IllegalArgumentException();
}
hostname = host;
this.port = port;
if (needResolved) {
// BEGIN android-added
SecurityManager smgr = System.getSecurityManager();
if(smgr != null) {
smgr.checkConnect(host, port);
}
// END android-added
try {
addr = InetAddress.getByName(hostname);
hostname = null;
} catch (UnknownHostException e) {
// Ignored
}
} else {
addr = null;
}
|
Methods Summary |
---|
public static java.net.InetSocketAddress | createUnresolved(java.lang.String host, int port)Creates an {@code InetSocketAddress} without trying to resolve the
hostname into an {@code InetAddress}. The address field is marked as
unresolved.
return new InetSocketAddress(host, port, false);
|
public final boolean | equals(java.lang.Object socketAddr)Compares two socket endpoints and returns true if they are equal. Two
socket endpoints are equal if the IP address or the hostname of both are
equal and they are bound to the same port.
if (this == socketAddr) {
return true;
}
if (!(socketAddr instanceof InetSocketAddress)) {
return false;
}
InetSocketAddress iSockAddr = (InetSocketAddress) socketAddr;
// check the ports as we always need to do this
if (port != iSockAddr.port) {
return false;
}
// we only use the hostnames in the comparison if the addrs were not
// resolved
if ((addr == null) && (iSockAddr.addr == null)) {
return hostname.equals(iSockAddr.hostname);
}
// addrs were resolved so use them for the comparison
if (addr == null) {
// if we are here we know iSockAddr is not null so just return
// false
return false;
}
return addr.equals(iSockAddr.addr);
|
public final java.net.InetAddress | getAddress()Gets the address of this socket.
return addr;
|
public final java.lang.String | getHostName()Gets the hostname of this socket.
return (null != addr) ? addr.getHostName() : hostname;
|
public final int | getPort()Gets the port number of this socket.
return port;
|
public final int | hashCode()Gets the hashcode of this socket.
if (addr == null) {
return hostname.hashCode() + port;
}
return addr.hashCode() + port;
|
public final boolean | isUnresolved()Returns whether this socket address is unresolved or not.
return addr == null;
|
private void | readObject(java.io.ObjectInputStream stream)
stream.defaultReadObject();
|
public java.lang.String | toString()Gets a string representation of this socket included the address and the
port number.
String host;
if (addr != null) {
host = addr.toString();
} else {
host = hostname;
}
return host + ":" + port; //$NON-NLS-1$
|