| java.lang.Object java.net.ServerSocket
ServerSocket | public class ServerSocket (Code) | | ServerSocket create connections between 'host' and 'client' machines. The
ServerSocket listens on a well known port and upon a connection request,
instantiates a 'host' sockets, which carries on future communication with the
requesting 'client' socket, so that the server socket may continue listening
for connection requests. They are passive objects, having no execution thread
of their own to listen on.
|
Constructor Summary | |
public | ServerSocket() Construct a ServerSocket, which is not bound to any port. | protected | ServerSocket(SocketImpl impl) | public | ServerSocket(int aport) Construct a ServerSocket, bound to the nominated port on the default
localhost. | public | ServerSocket(int aport, int backlog) Construct a ServerSocket, bound to the nominated port on the default
localhost. | public | ServerSocket(int aport, int backlog, InetAddress localAddr) Construct a ServerSocket, bound to the nominated local host/port. |
Method Summary | |
public Socket | accept() Retrieve the first connection request and answer the 'host' socket that
will conduct further communications with the requesting 'client' socket. | public void | bind(SocketAddress localAddr) Bind the ServerSocket to the nominated local host/port. | public void | bind(SocketAddress localAddr, int backlog) Bind the ServerSocket to the nominated local host/port. | void | checkListen(int aPort) Check whether the server may listen for connection requests on
aport . | public void | close() Close this server socket. | static int | defaultBacklog() Answer the default number of pending connections on a server socket. | public ServerSocketChannel | getChannel() | public InetAddress | getInetAddress() Answer the local IP address for this server socket. | public int | getLocalPort() Answer the local port for this server socket. | public SocketAddress | getLocalSocketAddress() Answer the local SocketAddress for this server socket, or null if the
socket is not bound. | public int | getReceiveBufferSize() Answer the socket receive buffer size (SO_RCVBUF). | public boolean | getReuseAddress() Get the state of the SO_REUSEADDR socket option. | public synchronized int | getSoTimeout() Answer the time-out period of this server socket. | final protected void | implAccept(Socket aSocket) Invoke the server socket implementation to accept a connection on the
newly created aSocket . | public boolean | isBound() Return if the server socket is bound to a local address and port. | public boolean | isClosed() Return if the server socket is closed. | public void | setPerformancePreferences(int connectionTime, int latency, int bandwidth) | public void | setReceiveBufferSize(int size) Set the socket receive buffer size. | public void | setReuseAddress(boolean reuse) Set the SO_REUSEADDR socket option. | public synchronized void | setSoTimeout(int timeout) Set the listen time-out period for this server socket. | public static synchronized void | setSocketFactory(SocketImplFactory aFactory) Set the server socket implementation factory. | public String | toString() Answers a string containing a concise, human-readable description of the
server socket. |
ServerSocket | public ServerSocket() throws IOException(Code) | | Construct a ServerSocket, which is not bound to any port. The default
number of pending connections may be backlogged.
See Also: Socket |
ServerSocket | public ServerSocket(int aport) throws IOException(Code) | | Construct a ServerSocket, bound to the nominated port on the default
localhost. The default number of pending connections may be backlogged.
Parameters: aport - the port number to listen for connection requests on See Also: Socket |
ServerSocket | public ServerSocket(int aport, int backlog) throws IOException(Code) | | Construct a ServerSocket, bound to the nominated port on the default
localhost. The number of pending connections that may be backlogged is a
specified.
Parameters: aport - the port number to listen for connection requests on Parameters: backlog - the number of pending connection requests, before requests arerejected See Also: Socket |
ServerSocket | public ServerSocket(int aport, int backlog, InetAddress localAddr) throws IOException(Code) | | Construct a ServerSocket, bound to the nominated local host/port. The
number of pending connections that may be backlogged is a specified.
Parameters: aport - the port number to listen for connection requests on Parameters: localAddr - the local machine address to bind on Parameters: backlog - the number of pending connection requests, before requests arerejected See Also: Socket |
accept | public Socket accept() throws IOException(Code) | | Retrieve the first connection request and answer the 'host' socket that
will conduct further communications with the requesting 'client' socket.
Socket the 'host' socket exception: IOException - if an error occurs while instantiating the 'host' socket |
bind | public void bind(SocketAddress localAddr) throws IOException(Code) | | Bind the ServerSocket to the nominated local host/port. The default
number of pending connections may be backlogged.
Parameters: localAddr - the local machine address and port to bind on exception: IllegalArgumentException - if the SocketAddress is not supported exception: IOException - if the socket is already bound, or a problem occurs duringthe bind |
bind | public void bind(SocketAddress localAddr, int backlog) throws IOException(Code) | | Bind the ServerSocket to the nominated local host/port. The number of
pending connections that may be backlogged is a specified.
Parameters: localAddr - the local machine address and port to bind on Parameters: backlog - the number of pending connection requests, before requests arerejected exception: IllegalArgumentException - if the SocketAddress is not supported exception: IOException - if the socket is already bound, or a problem occurs duringthe bind |
checkListen | void checkListen(int aPort)(Code) | | Check whether the server may listen for connection requests on
aport . Throw an exception if the port is outside the
valid range or does not satisfy the security policy.
Parameters: aPort - the candidate port to listen on |
close | public void close() throws IOException(Code) | | Close this server socket. Any attempt to connect to this socket
thereafter will fail.
|
defaultBacklog | static int defaultBacklog()(Code) | | Answer the default number of pending connections on a server socket.
int the default number of pending connection requests |
getChannel | public ServerSocketChannel getChannel()(Code) | | if ServerSocket is created by a ServerSocketChannel, returns the related
ServerSocketChannel
the related ServerSocketChannel if any |
getInetAddress | public InetAddress getInetAddress()(Code) | | Answer the local IP address for this server socket. Return null if the
socket is not bound. This is useful on multihomed hosts.
InetAddress the local address |
getLocalPort | public int getLocalPort()(Code) | | Answer the local port for this server socket. Return -1 if the socket is
not bound.
int the local port the server is listening on |
getLocalSocketAddress | public SocketAddress getLocalSocketAddress()(Code) | | Answer the local SocketAddress for this server socket, or null if the
socket is not bound. This is useful on multihomed hosts.
|
getReceiveBufferSize | public int getReceiveBufferSize() throws SocketException(Code) | | Answer the socket receive buffer size (SO_RCVBUF).
int socket receive buffer size |
getReuseAddress | public boolean getReuseAddress() throws SocketException(Code) | | Get the state of the SO_REUSEADDR socket option.
|
getSoTimeout | public synchronized int getSoTimeout() throws IOException(Code) | | Answer the time-out period of this server socket. This is the time the
server will wait listening for connections, before exiting.
int the listening timeout exception: SocketException - thrown if option cannot be retrieved |
implAccept | final protected void implAccept(Socket aSocket) throws IOException(Code) | | Invoke the server socket implementation to accept a connection on the
newly created aSocket .
Parameters: aSocket - the concrete socketImpl to accept the connection request on exception: IOException - thrown if connection cannot be accepted |
isBound | public boolean isBound()(Code) | | Return if the server socket is bound to a local address and port.
|
isClosed | public boolean isClosed()(Code) | | Return if the server socket is closed.
|
setPerformancePreferences | public void setPerformancePreferences(int connectionTime, int latency, int bandwidth)(Code) | | sets performance preference for connectionTime,latency and bandwidth
Parameters: connectionTime - the importance of connect time Parameters: latency - the importance of latency Parameters: bandwidth - the importance of bandwidth |
setReceiveBufferSize | public void setReceiveBufferSize(int size) throws SocketException(Code) | | Set the socket receive buffer size.
Parameters: size - the buffer size, in bytes exception: java.net.SocketException - If an error occurs while setting the size or the size isinvalid. |
setReuseAddress | public void setReuseAddress(boolean reuse) throws SocketException(Code) | | Set the SO_REUSEADDR socket option.
Parameters: reuse - the socket SO_REUSEADDR option setting |
setSoTimeout | public synchronized void setSoTimeout(int timeout) throws SocketException(Code) | | Set the listen time-out period for this server socket.
Parameters: timeout - the time to wait for a connection request exception: SocketException - thrown if an error occurs during setting the option |
setSocketFactory | public static synchronized void setSocketFactory(SocketImplFactory aFactory) throws IOException(Code) | | Set the server socket implementation factory. This method may only be
invoked with sufficient security and only once during the application
lifetime.
Parameters: aFactory - the streaming socket factory to be used for further socketinstantiations exception: IOException - thrown if the factory is already set |
toString | public String toString()(Code) | | Answers a string containing a concise, human-readable description of the
server socket. The port field is reported a zero, as there
is no connection formed to the server.
String the description |
|
|