java.lang.Object | ||
↳ | java.net.ServerSocket | |
↳ | sun.nio.ch.ServerSocketAdaptor |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Listens for a connection to be made to this socket and accepts
it.
| |||||||||||
Binds the
ServerSocket to a specific address
(IP address and port number). | |||||||||||
Binds the
ServerSocket to a specific address
(IP address and port number). | |||||||||||
Closes this socket.
| |||||||||||
Returns the unique
ServerSocketChannel object
associated with this socket, if any. | |||||||||||
Returns the local address of this server socket.
| |||||||||||
Returns the port number on which this socket is listening.
| |||||||||||
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.
| |||||||||||
Tests if SO_REUSEADDR is enabled.
| |||||||||||
Retrieve setting for SO_TIMEOUT.
| |||||||||||
Returns the binding state of the ServerSocket.
| |||||||||||
Returns the closed state of the ServerSocket.
| |||||||||||
Sets a default proposed value for the SO_RCVBUF option for sockets
accepted from this ServerSocket.
| |||||||||||
Enable/disable the SO_REUSEADDR socket option.
| |||||||||||
Enable/disable SO_TIMEOUT with the specified timeout, in
milliseconds.
| |||||||||||
Returns the implementation address and implementation port of
this socket as a
String . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
![]() | |||||||||||
![]() |
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.
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.
IOException |
---|
Binds the 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.
local | The IP address & port number to bind to. |
---|
IOException |
---|
Binds the 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 is equal or less
than 0, then the default value will be assumed.
local | The IP address & port number to bind to. |
---|---|
backlog | The listen backlog length. |
IOException |
---|
Closes this socket.
Any thread currently blocked in accept()
will throw
a SocketException
.
If this socket has an associated channel then the channel is closed as well.
IOException |
---|
Returns the unique ServerSocketChannel
object
associated with this socket, if any.
A server socket will have a channel if, and only if, the channel
itself was created via the ServerSocketChannel.open
method.
Returns the local address of this server socket.
null
if the socket is unbound.
Returns the port number on which this socket is listening.
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.
Note, the value actually set in the accepted socket is determined by
calling getReceiveBufferSize()
.
SocketException |
---|
Tests if SO_REUSEADDR is enabled.
boolean
indicating whether or not SO_REUSEADDR is enabled.SocketException |
---|
Retrieve setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).
SocketException |
---|
Returns the binding state of the ServerSocket.
Returns the closed state of the ServerSocket.
Sets a default proposed value for the SO_RCVBUF option for sockets
accepted from this ServerSocket. The value actually set
in the accepted socket must be determined by calling
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
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. |
---|
SocketException |
---|
Enable/disable the SO_REUSEADDR socket option.
When a TCP connection is closed the connection may remain in a timeout state for a period of time after the connection is closed (typically known as the TIME_WAIT state or 2MSL wait state). For applications using a well known socket address or port it may not be possible to bind a socket to the required SocketAddress if there is a connection in the timeout state involving the socket address or port.
Enabling SO_REUSEADDR prior to binding the socket
using bind(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 |
---|
SocketException |
---|
Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a non-zero timeout, a call to accept() for this ServerSocket will block for only this amount of time. If the timeout expires, a java.net.SocketTimeoutException is raised, though the ServerSocket is still valid. The option must be enabled prior to entering the blocking operation to have effect. The timeout must be > 0. A timeout of zero is interpreted as an infinite timeout.
timeout | the specified timeout, in milliseconds |
---|
SocketException |
---|
Returns the implementation address and implementation port of
this socket as a String
.