# InetSocketAddress

public class **InetSocketAddress** extends [SocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/SocketAddress.html)  
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.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/ServerSocket.html`

### Public Constructor Summary

|---|---|
|   | [InetSocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#InetSocketAddress(int))(int port) Creates a socket address where the IP address is the wildcard address and the port number a specified value. |
|   | [InetSocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#InetSocketAddress(java.net.InetAddress,%20int))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) addr, int port) Creates a socket address from an IP address and a port number. |
|   | [InetSocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#InetSocketAddress(java.lang.String,%20int))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) hostname, int port) Creates a socket address from a hostname and a port number. |

### Public Method Summary

|---|---|
| static [InetSocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html) | [createUnresolved](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#createUnresolved(java.lang.String,%20int))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, int port) Creates an unresolved socket address from a hostname and a port number. |
| final boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this object against the specified object. |
| final [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) | [getAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#getAddress())() Gets the `InetAddress`. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getHostName](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#getHostName())() Gets the `hostname`. |
| final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [getHostString](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#getHostString())() Returns the hostname, or the String form of the address if it doesn't have a hostname (it was created using a literal). |
| final int | [getPort](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#getPort())() Gets the port number. |
| final int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#hashCode())() Returns a hashcode for this socket address. |
| final boolean | [isUnresolved](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#isUnresolved())() Checks whether the address has been resolved or not. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#toString())() Constructs a string representation of this InetSocketAddress. |

### Inherited Method Summary

From class [java.lang.Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)

|---|---|
| [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) | [clone](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#clone())() Creates and returns a copy of this `Object`. |
| boolean | [equals](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#equals(java.lang.Object))([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj) Compares this instance with the specified object and indicates if they are equal. |
| void | [finalize](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#finalize())() Invoked when the garbage collector has detected that this instance is no longer reachable. |
| final [Class](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html)\<?\> | [getClass](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#getClass())() Returns the unique instance of `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Class.html` that represents this object's class. |
| int | [hashCode](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#hashCode())() Returns an integer hash code for this object. |
| final void | [notify](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notify())() Causes a thread which is waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| final void | [notifyAll](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#notifyAll())() Causes all threads which are waiting on this object's monitor (by means of calling one of the `wait()` methods) to be woken up. |
| [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) | [toString](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#toString())() Returns a string containing a concise, human-readable description of this object. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long,%20int))(long timeout, int nanos) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait(long))(long timeout) Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object or until the specified timeout expires. |
| final void | [wait](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html#wait())() Causes the calling thread to wait until another thread calls the `notify()` or `notifyAll()` method of this object. |

## Public Constructors

#### public
**InetSocketAddress**
(int port)

Creates a socket address where the IP address is the wildcard address
and the port number a specified value.


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.

<br />

##### Parameters

| port | The port number |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the port parameter is outside the specified range of valid port values. |
|---|---|

#### public
**InetSocketAddress**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) addr, int port)

Creates a socket address from an IP address and a port number.


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.

<br />

##### Parameters

| addr | The IP address |
| port | The port number |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the port parameter is outside the specified range of valid port values. |
|---|---|

#### public
**InetSocketAddress**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) hostname, int port)

Creates a socket address from a hostname and a port number.


An attempt will be made to resolve the hostname into an InetAddress.
If that attempt fails, the address will be flagged as *unresolved*.


If there is a security manager, its `checkConnect` method
is called with the host name as its argument to check the permission
to resolve it. This could result in a SecurityException.


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.

<br />

##### Parameters

| hostname | the Host name |
| port | The port number |
|---|---|

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the port parameter is outside the range of valid port values, or if the hostname parameter is null. |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager is present and permission to resolve the host name is denied. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#isUnresolved()`

## Public Methods

#### public static [InetSocketAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html)
**createUnresolved**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, int port)

Creates an unresolved socket address from a hostname and a port number.


No attempt will be made to resolve the hostname into an InetAddress.
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.

<br />

##### Parameters

| host | the Host name |
| port | The port number |
|---|---|

##### Returns

- a `InetSocketAddress` representing the unresolved socket address

##### Throws

| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the port parameter is outside the range of valid port values, or if the hostname parameter is null. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetSocketAddress.html#isUnresolved()`

#### public final boolean
**equals**
([Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html) obj)

Compares this object against the specified object.
The result is `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 and the port number
are compared.

Note: Hostnames are case insensitive. e.g. "FooBar" and "foobar" are
considered equal.

##### Parameters

| obj | the object to compare against. |
|---|---|

##### Returns

- `true` if the objects are the same; `false` otherwise.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html#equals(java.lang.Object)`

#### public final [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html)
**getAddress**
()

Gets the `InetAddress`.

##### Returns

- the InetAdress or `null` if it is unresolved.

#### public final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getHostName**
()

Gets the `hostname`.
Note: This method may trigger a name service reverse lookup if the
address was created with a literal IP address.

##### Returns

- the hostname part of the address.

#### public final [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**getHostString**
()

Returns the hostname, or the String form of the address if it
doesn't have a hostname (it was created using a literal).
This has the benefit of **not** attempting a reverse lookup.

##### Returns

- the hostname, or String representation of the address.

#### public final int
**getPort**
()

Gets the port number.

##### Returns

- the port number.

#### public final int
**hashCode**
()

Returns a hashcode for this socket address.

##### Returns

- a hash code value for this socket address.

#### public final boolean
**isUnresolved**
()

Checks whether the address has been resolved or not.

##### Returns

- `true` if the hostname couldn't be resolved into an `InetAddress`.

#### public [String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html)
**toString**
()

Constructs a string representation of this InetSocketAddress.
This String is constructed by calling toString() on the InetAddress
and concatenating the port number (with a colon). If the address
is unresolved then the part before the colon will only contain the hostname.

##### Returns

- a string representation of this object.