|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
An interface to an underlying server socket. This interface has many of the same methods as java.net.ServerSocket, but allows different server socket implementations to be plugged in.
| Method Summary | |
Socket |
accept()
Listens for a connection to be made to this socket and accepts it. |
void |
bind(java.net.SocketAddress endpoint)
Binds the ServerSocket to a specific address
(IP address and port number). |
void |
bind(java.net.SocketAddress endpoint,
int backlog)
Binds the ServerSocket to a specific address
(IP address and port number). |
void |
close()
Closes this socket. |
int |
getLocalPort()
Returns the port on which this socket is listening. |
java.net.SocketAddress |
getLocalSocketAddress()
Returns the address of the endpoint this socket is bound to, or null if it is not bound yet. |
int |
getReceiveBufferSize()
Gets the value of the SO_RCVBUF option for this ServerSocket, that is the proposed buffer size that will be used for Sockets accepted from this ServerSocket. |
boolean |
getReuseAddress()
Tests if SO_REUSEADDR is enabled. |
int |
getSoTimeout()
Retrive setting for SO_TIMEOUT. |
boolean |
isBound()
Returns the binding state of the ServerSocket. |
boolean |
isClosed()
Returns the closed state of the ServerSocket. |
void |
setReceiveBufferSize(int size)
Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket. |
void |
setReuseAddress(boolean on)
Enable/disable the SO_REUSEADDR socket option. |
void |
setSoTimeout(int timeout)
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. |
| Method Detail |
public void bind(java.net.SocketAddress endpoint)
throws java.io.IOException
ServerSocket to a specific address
(IP address and port number).
If the address is null, then the system will pick up
an ephemeral port and a valid local address to bind the socket.
endpoint - The IP address & port number to bind to.
java.lang.IllegalArgumentException - if endpoint is a
SocketAddress subclass not supported by this socket
java.io.IOException - if the bind operation fails, or if the socket
is already bound.
java.lang.SecurityException - if a SecurityManager is present and
its checkListen method doesn't allow the operation.
public void bind(java.net.SocketAddress endpoint,
int backlog)
throws java.io.IOException
ServerSocket to a specific address
(IP address and port number).
If the address is null, then the system will pick up
an ephemeral port and a valid local address to bind the socket.
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.
endpoint - The IP address & port number to bind to.backlog - The listen backlog length.
java.lang.IllegalArgumentException - if endpoint is a
SocketAddress subclass not supported by this socket
java.io.IOException - if the bind operation fails, or if the socket
is already bound.
java.lang.SecurityException - if a SecurityManager is present and
its checkListen method doesn't allow the operation.public boolean isBound()
public Socket accept()
throws java.io.IOException
A new Socket s is created and, if there
is a security manager,
the security manager's checkAccept method is called
with s.getInetAddress().getHostAddress() and
s.getPort()
as its arguments to ensure the operation is allowed.
This could result in a SecurityException.
java.io.IOException - if an I/O error occurs when waiting for a
connection.
java.lang.SecurityException - if a security manager exists and its
checkListen method doesn't allow the operation.
java.net.SocketTimeoutException - if a timeout was previously set with setSoTimeout and
the timeout has been reached.
java.nio.channels.IllegalBlockingModeException - if this socket has an associated channel, the channel is in
non-blocking mode, and there is no connection ready to be
acceptedSecurityManager.checkAccept(java.lang.String, int)
public void close()
throws java.io.IOException
accept() will throw
a SocketException.
If this socket has an associated channel then the channel is closed as well.
java.io.IOException - if an I/O error occurs when closing the socket.public boolean isClosed()
public int getLocalPort()
public java.net.SocketAddress getLocalSocketAddress()
null if it is not bound yet.
SocketAddress representing the local endpoint of this
socket, or null if it is not bound yet.getLocalPort(),
bind(java.net.SocketAddress)
public int getSoTimeout()
throws java.io.IOException
java.io.IOException - if an I/O error occurssetSoTimeout(int)
public void setSoTimeout(int timeout)
throws java.net.SocketException
timeout - the specified timeout, in milliseconds
java.net.SocketException - if there is an error in
the underlying protocol, such as a TCP error.getSoTimeout()
public boolean getReuseAddress()
throws java.net.SocketException
boolean indicating whether or not SO_REUSEADDR is enabled.
java.net.SocketException - if there is an error
in the underlying protocol, such as a TCP error.setReuseAddress(boolean)
public void setReuseAddress(boolean on)
throws java.net.SocketException
bind(java.net.SocketAddress) allows the socket to be
bound even though a previous connection is in a timeout
state.
When a ServerSocket is created the initial setting
of SO_REUSEADDR is not defined. Applications can
use getReuseAddress() to determine the initial
setting of SO_REUSEADDR.
The behaviour when SO_REUSEADDR is enabled or
disabled after a socket is bound (See isBound())
is not defined.
on - whether to enable or disable the socket option
java.net.SocketException - if an error occurs enabling or
disabling the SO_RESUEADDR socket option,
or the socket is closed.getReuseAddress(),
bind(java.net.SocketAddress),
isBound(),
isClosed()
public int getReceiveBufferSize()
throws java.net.SocketException
Note, the value actually set in the accepted socket is determined by
calling Socket.getReceiveBufferSize().
java.net.SocketException - if there is an error
in the underlying protocol, such as a TCP error.setReceiveBufferSize(int)
public void setReceiveBufferSize(int size)
throws java.net.SocketException
Socket.getReceiveBufferSize() after the socket
is returned by accept().
The value of SO_RCVBUF is used both to set the size of the internal
socket receive buffer, and to set the size of the TCP receive window
that is advertized to the remote peer.
It is possible to change the value subsequently, by calling
Socket.setReceiveBufferSize(int). However, if the application
wishes to allow a receive window larger than 64K bytes, as defined by RFC1323
then the proposed value must be set in the ServerSocket before
it is bound to a local address. This implies, that the ServerSocket must be
created with the no-argument constructor, then setReceiveBufferSize() must
be called and lastly the ServerSocket is bound to an address by calling bind().
Failure to do this will not cause an error, and the buffer size may be set to the
requested value but the TCP receive window in sockets accepted from
this ServerSocket will be no larger than 64K bytes.
size - the size to which to set the receive buffer
size. This value must be greater than 0.
java.net.SocketException - if there is an error
in the underlying protocol, such as a TCP error.
java.lang.IllegalArgumentException - if the
value is 0 or is negative.getReceiveBufferSize()
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||