java.net

Class InetSocketAddress

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

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 InetSocketAddresscreateUnresolved(String hostname, int port)
Creates an unresolved InetSocketAddress object.
booleanequals(Object obj)
Test if obj is a InetSocketAddress and has the same address and port
InetAddressgetAddress()
Returns the InetAddress or null if its unresolved
StringgetHostName()
Returns hostname
intgetPort()
Returns the port
inthashCode()
Returns the hashcode of the InetSocketAddress
booleanisUnresolved()
Checks wether the address has been resolved or not
StringtoString()
Returns the InetSocketAddress as string

Constructor Detail

InetSocketAddress

public InetSocketAddress(InetAddress addr, int port)
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)
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

Parameters: obj The obj to compare this address with.

Returns: True if obj is equal.

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

Returns: The hashcode for this address.

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

Returns: A string representation of this address.