ServerSocket

public class ServerSocket extends Object
implements Closeable
Known Direct Subclasses

This class represents a server-side socket that waits for incoming client connections. A ServerSocket handles the requests and sends back an appropriate reply. The actual tasks that a server socket must accomplish are implemented by an internal SocketImpl instance.

Public Constructor Summary

ServerSocket()
Constructs a new unbound ServerSocket.
ServerSocket(int port)
Constructs a new ServerSocket instance bound to the given port.
ServerSocket(int port, int backlog)
Constructs a new ServerSocket instance bound to the given port.
ServerSocket(int port, int backlog, InetAddress localAddress)
Constructs a new ServerSocket instance bound to the given localAddress and port.

Public Method Summary

Socket
accept()
Waits for an incoming request and blocks until the connection is opened.
void
bind(SocketAddress localAddr, int backlog)
Binds this server socket to the given local socket address.
void
bind(SocketAddress localAddr)
Binds this server socket to the given local socket address with a maximum backlog of 50 unaccepted connections.
void
close()
Closes this server socket and its implementation.
ServerSocketChannel
getChannel()
Returns this socket's ServerSocketChannel, if one exists.
InetAddress
getInetAddress()
Gets the local IP address of this server socket if this socket has ever been bound, null otherwise.
int
getLocalPort()
Gets the local port of this server socket or -1 if the socket is not bound.
SocketAddress
getLocalSocketAddress()
Gets the local socket address of this server socket or null if the socket is unbound.
int
getReceiveBufferSize()
Returns this socket's receive buffer size.
boolean
getReuseAddress()
Gets the value of the socket option SocketOptions.SO_REUSEADDR.
synchronized int
getSoTimeout()
Gets the socket accept timeout.
boolean
isBound()
Returns whether this server socket is bound to a local address and port or not.
boolean
isClosed()
Returns whether this server socket is closed or not.
void
setPerformancePreferences(int connectionTime, int latency, int bandwidth)
Sets performance preferences for connection time, latency and bandwidth.
void
setReceiveBufferSize(int size)
Sets this socket's receive buffer size.
void
setReuseAddress(boolean reuse)
Sets the value for the socket option SocketOptions.SO_REUSEADDR.
synchronized void
setSoTimeout(int timeout)
Sets the accept timeout in milliseconds for this socket.
synchronized static void
setSocketFactory(SocketImplFactory aFactory)
Sets the server socket implementation factory of this instance.
String
toString()
Returns a textual representation of this server socket including the address, port and the state.

Protected Method Summary

final void
implAccept(Socket aSocket)
Invokes the server socket implementation to accept a connection on the given socket aSocket.

Inherited Method Summary