|
JavaTM 2 Platform Std. Ed. v1.4.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.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.
Socket
,
ServerSocket
,
Serialized FormConstructor 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 | |
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 wether the address has been resolved or not. |
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.
port
- The port number
IllegalArgumentException
- if the port parameter is outside the specified
range of valid port values.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.
addr
- The IP addressport
- The port number
IllegalArgumentException
- if the port parameter is outside the specified
range of valid port values.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.
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.
hostname
- the Host nameport
- The port number
IllegalArgumentException
- if the port parameter is outside the range
of valid port values, or if the hostname parameter is null.isUnresolved()
Method Detail |
public final int getPort()
public final InetAddress getAddress()
InetAddress
.
null
if it is unresolved.public final String getHostName()
hostname
.
public final boolean isUnresolved()
true
if the hostname couldn't be resolved into
an InetAddress
.public String toString()
toString
in class Object
public final boolean equals(Object obj)
true
if and only if the argument is
not null
and it represents the same address as
this object.
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.
equals
in class Object
obj
- the object to compare against.
true
if the objects are the same;
false
otherwise.java.net.InetAddress#equals()
public final int hashCode()
hashCode
in class Object
Object.equals(java.lang.Object)
,
Hashtable
|
JavaTM 2 Platform Std. Ed. v1.4.0 |
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Java, Java 2D, and JDBC are trademarks or registered trademarks of Sun Microsystems, Inc. in the US and other countries.
Copyright 1993-2002 Sun Microsystems, Inc. 901 San Antonio Road
Palo Alto, California, 94303, U.S.A. All Rights Reserved.