Skip to content

Most visited

Recently visited

navigation
Added in API level 1

InetSocketAddress

public class InetSocketAddress
extends SocketAddress

java.lang.Object
   ↳ java.net.SocketAddress
     ↳ java.net.InetSocketAddress


This class represents the address of a socket endpoint described by a IP address and a port number. It is a concrete implementation of SocketAddress for IP.

Summary

Public constructors

InetSocketAddress(int port)

Creates a socket endpoint with the given port number port and no specified address.

InetSocketAddress(InetAddress address, int port)

Creates a socket endpoint with the given port number port and address.

InetSocketAddress(String host, int port)

Creates a socket endpoint with the given port number port and the hostname host.

Public methods

static InetSocketAddress createUnresolved(String host, int port)

Creates an InetSocketAddress without trying to resolve the hostname into an InetAddress.

final boolean equals(Object socketAddr)

Compares two socket endpoints and returns true if they are equal.

final InetAddress getAddress()

Returns the socket endpoint's address.

final String getHostName()

Returns the hostname, doing a reverse DNS lookup on the InetAddress if no hostname string was provided at construction time.

final String getHostString()

Returns the hostname if known, or the result of InetAddress.getHostAddress.

final int getPort()

Returns the socket endpoint's port.

final int hashCode()

Returns an integer hash code for this object.

final boolean isUnresolved()

Returns whether this socket address is unresolved or not.

String toString()

Returns a string containing the address (or the hostname for an unresolved InetSocketAddress) and port number.

Inherited methods

From class java.lang.Object

Public constructors

InetSocketAddress

Added in API level 1
InetSocketAddress (int port)

Creates a socket endpoint with the given port number port and no specified address. The range for valid port numbers is between 0 and 65535 inclusive.

Parameters
port int: the port number of the socket endpoint.

InetSocketAddress

Added in API level 1
InetSocketAddress (InetAddress address, 
                int port)

Creates a socket endpoint with the given port number port and address. The range for valid port numbers is between 0 and 65535 inclusive. If address is null the address is set to a wildcard address.

Parameters
address InetAddress: the address of the socket endpoint.
port int: the port number of the socket endpoint.

InetSocketAddress

Added in API level 1
InetSocketAddress (String host, 
                int port)

Creates a socket endpoint with the given port number port and the hostname host. The hostname is tried to be resolved and cannot be null. The range for valid port numbers is between 0 and 65535 inclusive.

Parameters
host String: the hostname of the socket endpoint.
port int: the port number of the socket endpoint.

Public methods

createUnresolved

Added in API level 1
InetSocketAddress createUnresolved (String host, 
                int port)

Creates an InetSocketAddress without trying to resolve the hostname into an InetAddress. The address field is marked as unresolved.

Parameters
host String: the hostname of the socket endpoint.
port int: the port number of the socket endpoint.
Returns
InetSocketAddress the created InetSocketAddress instance.
Throws
IllegalArgumentException if the hostname host is null or the port is not in the range between 0 and 65535.

equals

Added in API level 1
boolean equals (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.

Parameters
socketAddr Object: the object to be tested for equality.
Returns
boolean true if this socket endpoint and the given socket endpoint socketAddr are equal, false otherwise.

getAddress

Added in API level 1
InetAddress getAddress ()

Returns the socket endpoint's address.

Returns
InetAddress

getHostName

Added in API level 1
String getHostName ()

Returns the hostname, doing a reverse DNS lookup on the InetAddress if no hostname string was provided at construction time. Use getHostString() to avoid the reverse DNS lookup.

Returns
String

getHostString

Added in API level 19
String getHostString ()

Returns the hostname if known, or the result of InetAddress.getHostAddress. Unlike getHostName(), this method will never cause a DNS lookup.

Returns
String

getPort

Added in API level 1
int getPort ()

Returns the socket endpoint's port.

Returns
int

hashCode

Added in API level 1
int hashCode ()

Returns an integer hash code for this object. By contract, any two objects for which equals(Object) returns true must return the same hash code value. This means that subclasses of Object usually override both methods or neither method.

Note that hash values must not change over time unless information used in equals comparisons also changes.

See Writing a correct hashCode method if you intend implementing your own hashCode method.

Returns
int this object's hash code.

isUnresolved

Added in API level 1
boolean isUnresolved ()

Returns whether this socket address is unresolved or not.

Returns
boolean true if this socket address is unresolved, false otherwise.

toString

Added in API level 1
String toString ()

Returns a string containing the address (or the hostname for an unresolved InetSocketAddress) and port number. For example: "www.google.com/74.125.224.115:80" or "/127.0.0.1:80".

Returns
String a printable representation of this object.
This site uses cookies to store your preferences for site-specific language and display options.

Hooray!

This class requires API level or higher

This doc is hidden because your selected API level for the documentation is . You can change the documentation API level with the selector above the left navigation.

For more information about specifying the API level your app requires, read Supporting Different Platform Versions.