# SocketFactory

public abstract class **SocketFactory** extends [Object](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/Object.html)  

|---|---|---|
| Known Direct Subclasses [SSLSocketFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSocketFactory.html) |---|---| | [SSLSocketFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ssl/SSLSocketFactory.html) | `SSLSocketFactory`s create `SSLSocket`s. | |||

This class creates sockets. It may be subclassed by other factories,
which create particular subclasses of sockets and thus provide a general
framework for the addition of public socket-level functionality.

Socket factories are a simple way to capture a variety of policies
related to the sockets being constructed, producing such sockets in
a way which does not require special configuration of the code which
asks for the sockets:

- Due to polymorphism of both factories and sockets, different kinds of sockets can be used by the same application code just by passing it different kinds of factories.
- Factories can themselves be customized with parameters used in socket construction. So for example, factories could be customized to return sockets with different networking timeouts or security parameters already configured.
- The sockets returned to the application can be subclasses of java.net.Socket, so that they can directly expose new APIs for features such as compression, security, record marking, statistics collection, or firewall tunneling.

Factory classes are specified by environment-specific configuration
mechanisms. For example, the *getDefault* method could return
a factory that was appropriate for a particular user or applet, and a
framework could use a factory customized to its own purposes.

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/ServerSocketFactory.html`

### Protected Constructor Summary

|---|---|
|   | [SocketFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html#SocketFactory())() Creates a `SocketFactory`. |

### Public Method Summary

|---|---|
| abstract [Socket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html) | [createSocket](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html#createSocket(java.lang.String,%20int))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, int port) Creates a socket and connects it to the specified remote host at the specified remote port. |
| abstract [Socket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html) | [createSocket](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html#createSocket(java.net.InetAddress,%20int))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) host, int port) Creates a socket and connects it to the specified port number at the specified address. |
| abstract [Socket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html) | [createSocket](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html#createSocket(java.net.InetAddress,%20int,%20java.net.InetAddress,%20int))([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) address, int port, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) localAddress, int localPort) Creates a socket and connect it to the specified remote address on the specified remote port. |
| abstract [Socket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html) | [createSocket](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html#createSocket(java.lang.String,%20int,%20java.net.InetAddress,%20int))([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, int port, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) localHost, int localPort) Creates a socket and connects it to the specified remote host on the specified remote port. |
| [Socket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html) | [createSocket](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html#createSocket())() Creates an unconnected socket. |
| static [SocketFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html) | [getDefault](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html#getDefault())() Returns a copy of the environment's default socket factory. |

### 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. |

## Protected Constructors

#### protected
**SocketFactory**
()

Creates a `SocketFactory`.

## Public Methods

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

Creates a socket and connects it to the specified remote host
at the specified remote port. This socket is configured using
the socket options established for this factory.


If there is a security manager, its `checkConnect`
method is called with the host address and `port`
as its arguments. This could result in a SecurityException.

##### Parameters

| host | the server host name with which to connect, or `null` for the loopback address. |
| port | the server port |
|---|---|

##### Returns

- the `Socket`

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs when creating the socket |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and its `checkConnect` method doesn't allow the operation. |
| [UnknownHostException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/UnknownHostException.html) | if the host is not known |
| [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, which is between 0 and 65535, inclusive. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkConnect(java.lang.String,%20int)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html#Socket(java.lang.String,%20int)`

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

Creates a socket and connects it to the specified port number
at the specified address. This socket is configured using
the socket options established for this factory.


If there is a security manager, its `checkConnect`
method is called with the host address and `port`
as its arguments. This could result in a SecurityException.

##### Parameters

| host | the server host |
| port | the server port |
|---|---|

##### Returns

- the `Socket`

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs when creating the socket |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and its `checkConnect` method doesn't allow the operation. |
| [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, which is between 0 and 65535, inclusive. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `host` is null. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkConnect(java.lang.String,%20int)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html#Socket(java.net.InetAddress,%20int)`

#### public abstract [Socket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html)
**createSocket**
([InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) address, int port, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) localAddress, int localPort)

Creates a socket and connect it to the specified remote address
on the specified remote port. The socket will also be bound
to the local address and port suplied. The socket is configured using
the socket options established for this factory.


If there is a security manager, its `checkConnect`
method is called with the host address and `port`
as its arguments. This could result in a SecurityException.

##### Parameters

| address | the server network address |
| port | the server port |
| localAddress | the client network address |
| localPort | the client port |
|---|---|

##### Returns

- the `Socket`

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs when creating the socket |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and its `checkConnect` method doesn't allow the operation. |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the port parameter or localPort parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. |
| [NullPointerException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/NullPointerException.html) | if `address` is null. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkConnect(java.lang.String,%20int)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html#Socket(java.net.InetAddress,%20int,%20java.net.InetAddress,%20int)`

#### public abstract [Socket](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html)
**createSocket**
([String](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/String.html) host, int port, [InetAddress](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/InetAddress.html) localHost, int localPort)

Creates a socket and connects it to the specified remote host
on the specified remote port.
The socket will also be bound to the local address and port supplied.
This socket is configured using
the socket options established for this factory.


If there is a security manager, its `checkConnect`
method is called with the host address and `port`
as its arguments. This could result in a SecurityException.

##### Parameters

| host | the server host name with which to connect, or `null` for the loopback address. |
| port | the server port |
| localHost | the local address the socket is bound to |
| localPort | the local port the socket is bound to |
|---|---|

##### Returns

- the `Socket`

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if an I/O error occurs when creating the socket |
| [SecurityException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityException.html) | if a security manager exists and its `checkConnect` method doesn't allow the operation. |
| [UnknownHostException](https://developers.google.com/j2objc/javadoc/jre/reference/java/net/UnknownHostException.html) | if the host is not known |
| [IllegalArgumentException](https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/IllegalArgumentException.html) | if the port parameter or localPort parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/lang/SecurityManager.html#checkConnect(java.lang.String,%20int)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html#Socket(java.lang.String,%20int,%20java.net.InetAddress,%20int)`

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

Creates an unconnected socket.

##### Returns

- the unconnected socket

##### Throws

| [IOException](https://developers.google.com/j2objc/javadoc/jre/reference/java/io/IOException.html) | if the socket cannot be created |
|---|---|

##### See Also

- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html#connect(java.net.SocketAddress)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html#connect(java.net.SocketAddress,%20int)`
- `https://developers.google.com/j2objc/javadoc/jre/reference/java/net/Socket.html#Socket()`

#### public static [SocketFactory](https://developers.google.com/j2objc/javadoc/jre/reference/javax/net/SocketFactory.html)
**getDefault**
()

Returns a copy of the environment's default socket factory.

##### Returns

- the default `SocketFactory`