java.lang.Object | |
↳ | java.net.ServerSocket |
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 Constructors | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Constructs a new
ServerSocket instance which is not bound to any
port. | |||||||||||
Constructs a new
ServerSocket instance bound to the nominated
port on the localhost. | |||||||||||
Constructs a new
ServerSocket instance bound to the nominated
port on the localhost. | |||||||||||
Constructs a new
ServerSocket instance bound to the nominated
local host address and port. |
Public Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Waits for an incoming request and blocks until the connection is opened.
| |||||||||||
Binds this server socket to the given local socket address.
| |||||||||||
Binds this server socket to the given local socket address.
| |||||||||||
Closes this server socket and its implementation.
| |||||||||||
Gets the related channel if this instance was created by a
ServerSocketChannel . | |||||||||||
Gets the local IP address of this server socket or
null if the
socket is unbound. | |||||||||||
Gets the local port of this server socket or
-1 if the socket is
unbound. | |||||||||||
Gets the local socket address of this server socket or
null if
the socket is unbound. | |||||||||||
Gets the value for the receive buffer size socket option
SocketOptions.SO_RCVBUF . | |||||||||||
Gets the value of the socket option
SocketOptions.SO_REUSEADDR . | |||||||||||
Gets the timeout period of this server socket.
| |||||||||||
Returns whether this server socket is bound to a local address and port
or not.
| |||||||||||
Returns whether this server socket is closed or not.
| |||||||||||
Sets performance preferences for connection time, latency and bandwidth.
| |||||||||||
Sets the server socket receive buffer size
SocketOptions.SO_RCVBUF . | |||||||||||
Sets the value for the socket option
SocketOptions.SO_REUSEADDR . | |||||||||||
Sets the timeout period of this server socket.
| |||||||||||
Sets the server socket implementation factory of this instance.
| |||||||||||
Returns a textual representation of this server socket including the
address, port and the state.
|
Protected Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
Invokes the server socket implementation to accept a connection on the
given socket
aSocket . |
[Expand]
Inherited Methods | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|
From class java.lang.Object
|
Constructs a new ServerSocket
instance which is not bound to any
port. The default number of pending connections may be backlogged.
IOException | if an error occurs while creating the server socket. |
---|
Constructs a new ServerSocket
instance bound to the nominated
port on the localhost. The default number of pending connections may be
backlogged. If aport
is 0 a free port is assigned to the socket.
aport | the port number to listen for connection requests on. |
---|
IOException | if an error occurs while creating the server socket. |
---|
Constructs a new ServerSocket
instance bound to the nominated
port on the localhost. The number of pending connections that may be
backlogged is specified by backlog
. If aport
is 0 a free
port is assigned to the socket.
aport | the port number to listen for connection requests on. |
---|---|
backlog | the number of pending connection requests, before requests will be rejected. |
IOException | if an error occurs while creating the server socket. |
---|
Constructs a new ServerSocket
instance bound to the nominated
local host address and port. The number of pending connections that may
be backlogged is specified by backlog
. If aport
is 0 a
free port is assigned to the socket.
aport | the port number to listen for connection requests on. |
---|---|
backlog | the number of pending connection requests, before requests will be rejected. |
localAddr | the local machine address to bind on. |
IOException | if an error occurs while creating the server socket. |
---|
Waits for an incoming request and blocks until the connection is opened. This method returns a socket object representing the just opened connection.
IOException | if an error occurs while accepting a new connection. |
---|
Binds this server socket to the given local socket address. The default
number of pending connections may be backlogged. If the localAddr
is set to null
the socket will be bound to an available local
address on any free port of the system.
localAddr | the local address and port to bind on. |
---|
IllegalArgumentException | if the SocketAddress is not supported. |
---|---|
IOException | if the socket is already bound or a problem occurs during binding. |
Binds this server socket to the given local socket address. If the
localAddr
is set to null
the socket will be bound to an
available local address on any free port of the system. The value for
backlog
must e greater than 0
otherwise the default value
will be used.
localAddr | the local machine address and port to bind on. |
---|---|
backlog | the number of pending connection requests, before requests will be rejected. |
IllegalArgumentException | if the SocketAddress is not supported. |
---|---|
IOException | if the socket is already bound or a problem occurs during binding. |
Closes this server socket and its implementation. Any attempt to connect to this socket thereafter will fail.
IOException | if an error occurs while closing this socket. |
---|
Gets the related channel if this instance was created by a
ServerSocketChannel
. The current implementation returns always null
.
ServerSocketChannel
if any.
Gets the local IP address of this server socket or null
if the
socket is unbound. This is useful for multihomed hosts.
Gets the local port of this server socket or -1
if the socket is
unbound.
Gets the local socket address of this server socket or null
if
the socket is unbound. This is useful on multihomed hosts.
Gets the value for the receive buffer size socket option SocketOptions.SO_RCVBUF
.
SocketException | if an error occurs while reading the option value. |
---|
Gets the value of the socket option SocketOptions.SO_REUSEADDR
.
true
if the option is enabled, false
otherwise.SocketException | if an error occurs while reading the option value. |
---|
Gets the timeout period of this server socket. This is the time the server will wait listening for accepted connections before exiting.
IOException | if the option cannot be retrieved. |
---|
Returns whether this server socket is bound to a local address and port or not.
true
if this socket is bound, false
otherwise.
Returns whether this server socket is closed or not.
true
if this socket is closed, false
otherwise.
Sets performance preferences for connection time, latency and bandwidth.
This method does currently nothing.
connectionTime | the value representing the importance of a short connecting time. |
---|---|
latency | the value representing the importance of low latency. |
bandwidth | the value representing the importance of high bandwidth. |
Sets the server socket receive buffer size SocketOptions.SO_RCVBUF
.
size | the buffer size in bytes. |
---|
SocketException | if an error occurs while setting the size or the size is invalid. |
---|
Sets the value for the socket option SocketOptions.SO_REUSEADDR
.
reuse | the socket option setting. |
---|
SocketException | if an error occurs while setting the option value. |
---|
Sets the timeout period of this server socket. This is the time the server will wait listening for accepted connections before exiting. This value must be a positive number.
timeout | the listening timeout value of this server socket. |
---|
SocketException | if an error occurs while setting the option. |
---|
Sets the server socket implementation factory of this instance. This method may only be invoked with sufficient security privilege and only once during the application lifetime.
aFactory | the streaming socket factory to be used for further socket instantiations. |
---|
IOException | if the factory could not be set or is already set. |
---|
Returns a textual representation of this server socket including the
address, port and the state. The port field is set to 0
if there
is no connection to the server socket.
Invokes the server socket implementation to accept a connection on the
given socket aSocket
.
aSocket | the concrete SocketImpl to accept the connection
request on. |
---|
IOException | if the connection cannot be accepted. |
---|