# ServerSocketFactory

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  
Summary:[Protected Ctors](https://developer.android.com/reference/javax/net/ServerSocketFactory#proctors)\|[Methods](https://developer.android.com/reference/javax/net/ServerSocketFactory#pubmethods)\|[Inherited Methods](https://developer.android.com/reference/javax/net/ServerSocketFactory#inhmethods)  

# ServerSocketFactory

`
public


abstract
class
ServerSocketFactory
`  
`

extends `[Object](https://developer.android.com/reference/java/lang/Object)`


``


`

|---|-------------------------------|
| [java.lang.Object](https://developer.android.com/reference/java/lang/Object) ||
| ↳ | javax.net.ServerSocketFactory |

|------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| Known direct subclasses [SSLServerSocketFactory](https://developer.android.com/reference/javax/net/ssl/SSLServerSocketFactory) |--------------------------------------------------------------------------------------------------------|-----------------------------------------------------| | [SSLServerSocketFactory](https://developer.android.com/reference/javax/net/ssl/SSLServerSocketFactory) | `SSLServerSocketFactory`s create`SSLServerSocket`s. | |

<br />

*** ** * ** ***

This class creates server sockets. It may be subclassed by other factories, which create particular types of server sockets. This provides a general framework for the addition of public socket-level functionality. It is the server side analogue of a socket factory, and similarly provides a way to capture a variety of policies related to the sockets being constructed.

Like socket factories, server Socket factory instances have methods used to create sockets. There is also an environment specific default server socket factory; frameworks will often use their own customized factory.  
**See also:**

- [SocketFactory](https://developer.android.com/reference/javax/net/SocketFactory)

## Summary

|                                                                   ### Protected constructors                                                                   ||
|-------------------------------------------------------------------------------------------------------------------------------------------------------------|---|
| ` `[ServerSocketFactory](https://developer.android.com/reference/javax/net/ServerSocketFactory#ServerSocketFactory())`() ` Creates a server socket factory. |

|                                                                                                                                                                                                                                 ### Public methods                                                                                                                                                                                                                                  ||
|--------------------------------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------|
| ` abstract `[ServerSocket](https://developer.android.com/reference/java/net/ServerSocket)              | ` `[createServerSocket](https://developer.android.com/reference/javax/net/ServerSocketFactory#createServerSocket(int))`(int port) ` Returns a server socket bound to the specified port.                                                                                                                                                                                    |
| ` `[ServerSocket](https://developer.android.com/reference/java/net/ServerSocket)                       | ` `[createServerSocket](https://developer.android.com/reference/javax/net/ServerSocketFactory#createServerSocket())`() ` Returns an unbound server socket.                                                                                                                                                                                                                  |
| ` abstract `[ServerSocket](https://developer.android.com/reference/java/net/ServerSocket)              | ` `[createServerSocket](https://developer.android.com/reference/javax/net/ServerSocketFactory#createServerSocket(int,%20int,%20java.net.InetAddress))`(int port, int backlog, `[InetAddress](https://developer.android.com/reference/java/net/InetAddress)` ifAddress) ` Returns a server socket bound to the specified port, with a specified listen backlog and local IP. |
| ` abstract `[ServerSocket](https://developer.android.com/reference/java/net/ServerSocket)              | ` `[createServerSocket](https://developer.android.com/reference/javax/net/ServerSocketFactory#createServerSocket(int,%20int))`(int port, int backlog) ` Returns a server socket bound to the specified port, and uses the specified connection backlog.                                                                                                                     |
| ` static `[ServerSocketFactory](https://developer.android.com/reference/javax/net/ServerSocketFactory) | ` `[getDefault](https://developer.android.com/reference/javax/net/ServerSocketFactory#getDefault())`() ` Returns a copy of the environment's default socket factory.                                                                                                                                                                                                        |

| ### Inherited methods |
|-----------------------|---|
| From class` `[java.lang.Object](https://developer.android.com/reference/java/lang/Object)` ` |--------------------------------------------------------------------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| | ` `[Object](https://developer.android.com/reference/java/lang/Object)          | ` `[clone](https://developer.android.com/reference/java/lang/Object#clone())`() ` Creates and returns a copy of this object.                                                                                                                                                      | | ` boolean`                                                                     | ` `[equals](https://developer.android.com/reference/java/lang/Object#equals(java.lang.Object))`(`[Object](https://developer.android.com/reference/java/lang/Object)` obj) ` Indicates whether some other object is "equal to" this one.                                           | | ` void`                                                                        | ` `[finalize](https://developer.android.com/reference/java/lang/Object#finalize())`() ` Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.                                                          | | ` final `[Class](https://developer.android.com/reference/java/lang/Class)`<?>` | ` `[getClass](https://developer.android.com/reference/java/lang/Object#getClass())`() ` Returns the runtime class of this`Object`.                                                                                                                                                | | ` int`                                                                         | ` `[hashCode](https://developer.android.com/reference/java/lang/Object#hashCode())`() ` Returns a hash code value for the object.                                                                                                                                                 | | ` final void`                                                                  | ` `[notify](https://developer.android.com/reference/java/lang/Object#notify())`() ` Wakes up a single thread that is waiting on this object's monitor.                                                                                                                            | | ` final void`                                                                  | ` `[notifyAll](https://developer.android.com/reference/java/lang/Object#notifyAll())`() ` Wakes up all threads that are waiting on this object's monitor.                                                                                                                         | | ` `[String](https://developer.android.com/reference/java/lang/String)          | ` `[toString](https://developer.android.com/reference/java/lang/Object#toString())`() ` Returns a string representation of the object.                                                                                                                                            | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long,%20int))`(long timeoutMillis, int nanos) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed. | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait(long))`(long timeoutMillis) ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*, or until a certain amount of real time has elapsed.                   | | ` final void`                                                                  | ` `[wait](https://developer.android.com/reference/java/lang/Object#wait())`() ` Causes the current thread to wait until it is awakened, typically by being*notified* or*interrupted*.                                                                                             | ||

## Protected constructors

### ServerSocketFactory

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
protected ServerSocketFactory ()
```

Creates a server socket factory.

<br />

## Public methods

### createServerSocket

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract ServerSocket createServerSocket (int port)
```

Returns a server socket bound to the specified port. The socket is configured with the socket options (such as accept timeout) given to this factory.

If there is a security manager, its`checkListen`method is called with the`port`argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

<br />

|                 Parameters                  ||
|--------|-------------------------------------|
| `port` | `int`: the port to listen to <br /> |

|                                                 Returns                                                 ||
|-------------------------------------------------------------------------------|--------------------------|
| [ServerSocket](https://developer.android.com/reference/java/net/ServerSocket) | the`ServerSocket` <br /> |

|                                                                                                           Throws                                                                                                            ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException)                             | for networking errors                                                                                               |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)               | if a security manager exists and its`checkListen`method doesn't allow the operation.                                |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. |

**See also:**

- [SecurityManager.checkListen(int)](https://developer.android.com/reference/java/lang/SecurityManager#checkListen(int))
- [ServerSocket.ServerSocket(int)](https://developer.android.com/reference/java/net/ServerSocket#ServerSocket(int))  

### createServerSocket

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public ServerSocket createServerSocket ()
```

Returns an unbound server socket. The socket is configured with the socket options (such as accept timeout) given to this factory.

<br />

|                                                 Returns                                                  ||
|-------------------------------------------------------------------------------|---------------------------|
| [ServerSocket](https://developer.android.com/reference/java/net/ServerSocket) | the unbound socket <br /> |

|                                                   Throws                                                    ||
|----------------------------------------------------------------------------|---------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException) | if the socket cannot be created |

**See also:**

- [ServerSocket.bind(java.net.SocketAddress)](https://developer.android.com/reference/java/net/ServerSocket#bind(java.net.SocketAddress))
- [ServerSocket.bind(java.net.SocketAddress, int)](https://developer.android.com/reference/java/net/ServerSocket#bind(java.net.SocketAddress,%20int))
- [ServerSocket.ServerSocket()](https://developer.android.com/reference/java/net/ServerSocket#ServerSocket())  

### createServerSocket

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract ServerSocket createServerSocket (int port, 
                int backlog, 
                InetAddress ifAddress)
```

Returns a server socket bound to the specified port, with a specified listen backlog and local IP.

The`ifAddress`argument can be used on a multi-homed host for a`ServerSocket`that will only accept connect requests to one of its addresses. If`ifAddress`is null, it will accept connections on all local addresses. The socket is configured with the socket options (such as accept timeout) given to this factory.

The`backlog`argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.

If there is a security manager, its`checkListen`method is called with the`port`argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

<br />

|                               Parameters                                ||
|-------------|------------------------------------------------------------|
| `port`      | `int`: the port to listen to <br />                        |
| `backlog`   | `int`: how many connections are queued <br />              |
| `ifAddress` | `InetAddress`: the network interface address to use <br /> |

|                                                 Returns                                                 ||
|-------------------------------------------------------------------------------|--------------------------|
| [ServerSocket](https://developer.android.com/reference/java/net/ServerSocket) | the`ServerSocket` <br /> |

|                                                                                                           Throws                                                                                                            ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException)                             | for networking errors                                                                                               |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)               | if a security manager exists and its`checkListen`method doesn't allow the operation.                                |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. |

**See also:**

- [SecurityManager.checkListen(int)](https://developer.android.com/reference/java/lang/SecurityManager#checkListen(int))
- [ServerSocket.ServerSocket(int, int, java.net.InetAddress)](https://developer.android.com/reference/java/net/ServerSocket#ServerSocket(int,%20int,%20java.net.InetAddress))  

### createServerSocket

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public abstract ServerSocket createServerSocket (int port, 
                int backlog)
```

Returns a server socket bound to the specified port, and uses the specified connection backlog. The socket is configured with the socket options (such as accept timeout) given to this factory.

The`backlog`argument must be a positive value greater than 0. If the value passed if equal or less than 0, then the default value will be assumed.

If there is a security manager, its`checkListen`method is called with the`port`argument as its argument to ensure the operation is allowed. This could result in a SecurityException.

<br />

|                        Parameters                        ||
|-----------|-----------------------------------------------|
| `port`    | `int`: the port to listen to <br />           |
| `backlog` | `int`: how many connections are queued <br /> |

|                                                 Returns                                                 ||
|-------------------------------------------------------------------------------|--------------------------|
| [ServerSocket](https://developer.android.com/reference/java/net/ServerSocket) | the`ServerSocket` <br /> |

|                                                                                                           Throws                                                                                                            ||
|--------------------------------------------------------------------------------------------------------|---------------------------------------------------------------------------------------------------------------------|
| [IOException](https://developer.android.com/reference/java/io/IOException)                             | for networking errors                                                                                               |
| [SecurityException](https://developer.android.com/reference/java/lang/SecurityException)               | if a security manager exists and its`checkListen`method doesn't allow the operation.                                |
| [IllegalArgumentException](https://developer.android.com/reference/java/lang/IllegalArgumentException) | if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive. |

**See also:**

- [SecurityManager.checkListen(int)](https://developer.android.com/reference/java/lang/SecurityManager#checkListen(int))
- [ServerSocket.ServerSocket(int, int)](https://developer.android.com/reference/java/net/ServerSocket#ServerSocket(int,%20int))  

### getDefault

Added in[API level 1](https://developer.android.com/guide/topics/manifest/uses-sdk-element#ApiLevels)  

```
public static ServerSocketFactory getDefault ()
```

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

<br />

|                                                            Returns                                                            ||
|----------------------------------------------------------------------------------------------|---------------------------------|
| [ServerSocketFactory](https://developer.android.com/reference/javax/net/ServerSocketFactory) | the`ServerSocketFactory` <br /> |