ServerSocketFactory

public abstract class ServerSocketFactory
extends Object

java.lang.Object
   ↳ javax.net.ServerSocketFactory
SSLServerSocketFactory SSLServerSocketFactorys create SSLServerSockets. 


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:

Summary

Protected constructors

ServerSocketFactory()

Creates a server socket factory.

Public methods

abstract ServerSocket createServerSocket(int port)

Returns a server socket bound to the specified port.

ServerSocket createServerSocket()

Returns an unbound server socket.

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.

abstract ServerSocket createServerSocket(int port, int backlog)

Returns a server socket bound to the specified port, and uses the specified connection backlog.

static ServerSocketFactory getDefault()

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

Inherited methods

Object clone()

Creates and returns a copy of this object.

boolean equals(Object obj)

Indicates whether some other object is "equal to" this one.

void finalize()

Called by the garbage collector on an object when garbage collection determines that there are no more references to the object.

final Class<?> getClass()

Returns the runtime class of this Object.

int hashCode()

Returns a hash code value for the object.

final void notify()

Wakes up a single thread that is waiting on this object's monitor.

final void notifyAll()

Wakes up all threads that are waiting on this object's monitor.

String toString()

Returns a string representation of the object.

final void wait(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(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()

Causes the current thread to wait until it is awakened, typically by being notified or interrupted.

Protected constructors

ServerSocketFactory

Added in API level 1
protected ServerSocketFactory ()

Creates a server socket factory.

Public methods

createServerSocket

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

Parameters
port int: the port to listen to

Returns
ServerSocket the ServerSocket

Throws
IOException for networking errors
SecurityException if a security manager exists and its checkListen method doesn't allow the operation.
IllegalArgumentException if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.

createServerSocket

Added in API level 1
public ServerSocket createServerSocket ()

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

Returns
ServerSocket the unbound socket

Throws
IOException if the socket cannot be created

createServerSocket

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

Parameters
port int: the port to listen to

backlog int: how many connections are queued

ifAddress InetAddress: the network interface address to use

Returns
ServerSocket the ServerSocket

Throws
IOException for networking errors
SecurityException if a security manager exists and its checkListen method doesn't allow the operation.
IllegalArgumentException if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.

createServerSocket

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

Parameters
port int: the port to listen to

backlog int: how many connections are queued

Returns
ServerSocket the ServerSocket

Throws
IOException for networking errors
SecurityException if a security manager exists and its checkListen method doesn't allow the operation.
IllegalArgumentException if the port parameter is outside the specified range of valid port values, which is between 0 and 65535, inclusive.

getDefault

Added in API level 1
public static ServerSocketFactory getDefault ()

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

Returns
ServerSocketFactory the ServerSocketFactory