java.net
Class InetSocketAddress

java.lang.Object
  extended by java.net.SocketAddress
      extended by java.net.InetSocketAddress
All Implemented Interfaces:
Serializable

public class InetSocketAddress
extends SocketAddress

InetSocketAddress instances represent socket addresses in the java.nio package. They encapsulate a InetAddress and a port number.

Since:
1.4
See Also:
Serialized Form

Constructor Summary
InetSocketAddress(InetAddress addr, int port)
          Constructs an InetSocketAddress instance.
InetSocketAddress(int port)
          Constructs an InetSocketAddress instance.
InetSocketAddress(String hostname, int port)
          Constructs an InetSocketAddress instance.
 
Method Summary
static InetSocketAddress createUnresolved(String hostname, int port)
          Creates an unresolved InetSocketAddress object.
 boolean equals(Object obj)
          Test if obj is a InetSocketAddress and has the same address and port
 InetAddress getAddress()
          Returns the InetAddress or null if its unresolved
 String getHostName()
          Returns hostname
 int getPort()
          Returns the port
 int hashCode()
          Returns the hashcode of the InetSocketAddress
 boolean isUnresolved()
          Checks wether the address has been resolved or not
 String toString()
          Returns the InetSocketAddress as string
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
 

Constructor Detail

InetSocketAddress

public InetSocketAddress(InetAddress addr,
                         int port)
                  throws IllegalArgumentException
Constructs an InetSocketAddress instance.

Parameters:
addr - Address of the socket
port - Port if the socket
Throws:
IllegalArgumentException - If the port number is illegel

InetSocketAddress

public InetSocketAddress(int port)
                  throws IllegalArgumentException
Constructs an InetSocketAddress instance.

Parameters:
port - Port if the socket
Throws:
IllegalArgumentException - If the port number is illegal

InetSocketAddress

public InetSocketAddress(String hostname,
                         int port)
Constructs an InetSocketAddress instance.

Parameters:
hostname - The hostname for the socket address
port - The port for the socket address
Throws:
IllegalArgumentException - If the port number is illegal or the hostname argument is null
Method Detail

createUnresolved

public static InetSocketAddress createUnresolved(String hostname,
                                                 int port)
Creates an unresolved InetSocketAddress object.

Parameters:
hostname - The hostname for the socket address
port - The port for the socket address
Throws:
IllegalArgumentException - If the port number is illegal or the hostname argument is null
Since:
1.5

equals

public final boolean equals(Object obj)
Test if obj is a InetSocketAddress and has the same address and port

Overrides:
equals in class Object
Parameters:
obj - The obj to compare this address with.
Returns:
True if obj is equal.
See Also:
Object.hashCode()

getAddress

public final InetAddress getAddress()
Returns the InetAddress or null if its unresolved

Returns:
The IP address of this address.

getHostName

public final String getHostName()
Returns hostname

Returns:
The hostname of this address.

getPort

public final int getPort()
Returns the port

Returns:
The port of this address.

hashCode

public final int hashCode()
Returns the hashcode of the InetSocketAddress

Overrides:
hashCode in class Object
Returns:
The hashcode for this address.
See Also:
Object.equals(Object), System.identityHashCode(Object)

isUnresolved

public final boolean isUnresolved()
Checks wether the address has been resolved or not

Returns:
True if address is unresolved.

toString

public String toString()
Returns the InetSocketAddress as string

Overrides:
toString in class Object
Returns:
A string representation of this address.
See Also:
Object.getClass(), Object.hashCode(), Class.getName(), Integer.toHexString(int)