APIdia Launch Partner
Top Fields Constructors Methods
sun.nio.ch

pack-priv Class ServerSocketAdaptor

extends ServerSocket
Class Inheritance
Imports
java.io.IOException, java.net.InetAddress, .InetSocketAddress, .ServerSocket, .Socket, .SocketAddress, .SocketException, .SocketOption, .StandardSocketOptions, java.nio.channels.IllegalBlockingModeException, .ServerSocketChannel, .SocketChannel, java.util.Set

Field Summary

Modifier and TypeField and Description
private final ServerSocketChannelImpl
private volatile int

Constructor Summary

AccessConstructor and Description
private

Method Summary

Modifier and TypeMethod and Description
public Socket
accept()

Overrides java.net.ServerSocket.accept.

Listens for a connection to be made to this socket and accepts it.

public void
bind(SocketAddress local)

Overrides java.net.ServerSocket.bind.

Binds the ServerSocket to a specific address (IP address and port number).

public void
bind(SocketAddress local, int backlog)

Overrides java.net.ServerSocket.bind.

Binds the ServerSocket to a specific address (IP address and port number).

public void
close()

Overrides java.net.ServerSocket.close.

Implements java.io.Closeable.close.

Closes this socket.

pack-priv static ServerSocket
public ServerSocketChannel
getChannel()

Overrides java.net.ServerSocket.getChannel.

Returns the unique java.nio.channels.ServerSocketChannel object associated with this socket, if any.

public InetAddress
getInetAddress()

Overrides java.net.ServerSocket.getInetAddress.

Returns the local address of this server socket.

public int
getLocalPort()

Overrides java.net.ServerSocket.getLocalPort.

Returns the port number on which this socket is listening.

public <T> T
getOption(SocketOption<T> name)

Overrides java.net.ServerSocket.getOption.

Returns the value of a socket option.

public int
getReceiveBufferSize()

Overrides java.net.ServerSocket.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.

public boolean
public int
public boolean
isBound()

Overrides java.net.ServerSocket.isBound.

Returns the binding state of the ServerSocket.

public boolean
isClosed()

Overrides java.net.ServerSocket.isClosed.

Returns the closed state of the ServerSocket.

public <T> ServerSocket
setOption(SocketOption<T> name, T value)

Overrides java.net.ServerSocket.setOption.

Sets the value of a socket option.

public void
setReceiveBufferSize(int size)

Overrides java.net.ServerSocket.setReceiveBufferSize.

Sets a default proposed value for the SO_RCVBUF option for sockets accepted from this ServerSocket.

public void
setReuseAddress(boolean on)

Overrides java.net.ServerSocket.setReuseAddress.

Enable/disable the SO_REUSEADDR socket option.

public void
setSoTimeout(int timeout)

Overrides java.net.ServerSocket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds.

public Set<SocketOption<?>>
supportedOptions()

Overrides java.net.ServerSocket.supportedOptions.

Returns a set of the socket options supported by this server socket.

public String
toString()

Overrides java.net.ServerSocket.toString.

Returns the implementation address and implementation port of this socket as a String.

Inherited from java.net.ServerSocket:
getLocalSocketAddressimplAcceptsetPerformancePreferencessetSocketFactory

Field Detail

sscback to summary
private final ServerSocketChannelImpl ssc
timeoutback to summary
private volatile int timeout

Constructor Detail

ServerSocketAdaptorback to summary
private ServerSocketAdaptor(ServerSocketChannelImpl ssc)

Method Detail

acceptback to summary
public Socket accept() throws IOException

Overrides java.net.ServerSocket.accept.

Doc from java.net.ServerSocket.accept.

Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.

This method is interruptible in the following circumstances:

  1. The socket is associated with a ServerSocketChannel. In that case, interrupting a thread accepting a connection will close the underlying channel and cause this method to throw java.nio.channels.ClosedByInterruptException with the thread's interrupted status set.
  2. The socket uses the system-default socket implementation and a virtual thread is accepting a connection. In that case, interrupting the virtual thread will cause it to wakeup and close the socket. This method will then throw SocketException with the thread's interrupted status set.
Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when waiting for a connection, the socket is not bound or the socket is closed.
bindback to summary
public void bind(SocketAddress local) throws IOException

Overrides java.net.ServerSocket.bind.

Doc from java.net.ServerSocket.bind.

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.

Annotations
@Override
Exceptions
IOException:
if the bind operation fails, the socket is already bound or the socket is closed.
bindback to summary
public void bind(SocketAddress local, int backlog) throws IOException

Overrides java.net.ServerSocket.bind.

Doc from java.net.ServerSocket.bind.

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 is the requested maximum number of pending connections on the socket. Its exact semantics are implementation specific. In particular, an implementation may impose a maximum length or may choose to ignore the parameter altogether. The value provided should be greater than 0. If it is less than or equal to 0, then an implementation specific default will be used.

Annotations
@Override
Exceptions
IOException:
if the bind operation fails, the socket is already bound or the socket is closed.
closeback to summary
public void close() throws IOException

Overrides java.net.ServerSocket.close.

Implements java.io.Closeable.close.

Doc from java.net.ServerSocket.close.

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.

Once closed, several of the methods defined by this class will throw an exception if invoked on the closed socket.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs when closing the socket.
createback to summary
pack-priv static ServerSocket create(ServerSocketChannelImpl ssc)
getChannelback to summary
public ServerSocketChannel getChannel()

Overrides java.net.ServerSocket.getChannel.

Doc from java.net.ServerSocket.getChannel.

Returns the unique java.nio.channels.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.

Annotations
@Override
getInetAddressback to summary
public InetAddress getInetAddress()

Overrides java.net.ServerSocket.getInetAddress.

Doc from java.net.ServerSocket.getInetAddress.

Returns the local address of this server socket.

If the socket was bound prior to being closed, then this method will continue to return the local address after the socket is closed.

Annotations
@Override
getLocalPortback to summary
public int getLocalPort()

Overrides java.net.ServerSocket.getLocalPort.

Doc from java.net.ServerSocket.getLocalPort.

Returns the port number on which this socket is listening.

If the socket was bound prior to being closed, then this method will continue to return the port number after the socket is closed.

Annotations
@Override
getOptionback to summary
public <T> T getOption(SocketOption<T> name) throws IOException

Overrides java.net.ServerSocket.getOption.

Doc from java.net.ServerSocket.getOption.

Returns the value of a socket option.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs, or if the socket is closed.
getReceiveBufferSizeback to summary
public int getReceiveBufferSize() throws SocketException

Overrides java.net.ServerSocket.getReceiveBufferSize.

Doc from java.net.ServerSocket.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.

Note, the value actually set in the accepted socket is determined by calling Socket#getReceiveBufferSize().

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
getReuseAddressback to summary
public boolean getReuseAddress() throws SocketException

Overrides java.net.ServerSocket.getReuseAddress.

Doc from java.net.ServerSocket.getReuseAddress.

Tests if SO_REUSEADDR is enabled.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
getSoTimeoutback to summary
public int getSoTimeout() throws SocketException

Overrides java.net.ServerSocket.getSoTimeout.

Doc from java.net.ServerSocket.getSoTimeout.

Retrieve setting for SO_TIMEOUT. 0 returns implies that the option is disabled (i.e., timeout of infinity).

Annotations
@Override
isBoundback to summary
public boolean isBound()

Overrides java.net.ServerSocket.isBound.

Doc from java.net.ServerSocket.isBound.

Returns the binding state of the ServerSocket.

If the socket was bound prior to being closed, then this method will continue to return true after the socket is closed.

Annotations
@Override
isClosedback to summary
public boolean isClosed()

Overrides java.net.ServerSocket.isClosed.

Doc from java.net.ServerSocket.isClosed.

Returns the closed state of the ServerSocket.

Annotations
@Override
setOptionback to summary
public <T> ServerSocket setOption(SocketOption<T> name, T value) throws IOException

Overrides java.net.ServerSocket.setOption.

Doc from java.net.ServerSocket.setOption.

Sets the value of a socket option.

Annotations
@Override
Exceptions
IOException:
if an I/O error occurs, or if the socket is closed.
setReceiveBufferSizeback to summary
public void setReceiveBufferSize(int size) throws SocketException

Overrides java.net.ServerSocket.setReceiveBufferSize.

Doc from java.net.ServerSocket.setReceiveBufferSize.

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 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 advertised 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.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
setReuseAddressback to summary
public void setReuseAddress(boolean on) throws SocketException

Overrides java.net.ServerSocket.setReuseAddress.

Doc from java.net.ServerSocket.setReuseAddress.

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.

Annotations
@Override
Exceptions
SocketException:
if an error occurs enabling or disabling the SO_REUSEADDR socket option, or the socket is closed.
setSoTimeoutback to summary
public void setSoTimeout(int timeout) throws SocketException

Overrides java.net.ServerSocket.setSoTimeout.

Doc from java.net.ServerSocket.setSoTimeout.

Enable/disable SO_TIMEOUT with the specified timeout, in milliseconds. With this option set to a positive timeout value, 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. A timeout of zero is interpreted as an infinite timeout. The option must be enabled prior to entering the blocking operation to have effect.

Annotations
@Override
Exceptions
SocketException:
if there is an error in the underlying protocol, such as a TCP error, or the socket is closed.
supportedOptionsback to summary
public Set<SocketOption<?>> supportedOptions()

Overrides java.net.ServerSocket.supportedOptions.

Doc from java.net.ServerSocket.supportedOptions.

Returns a set of the socket options supported by this server socket. This method will continue to return the set of options even after the socket has been closed.

Annotations
@Override
toStringback to summary
public String toString()

Overrides java.net.ServerSocket.toString.

Doc from java.net.ServerSocket.toString.

Returns the implementation address and implementation port of this socket as a String.

Annotations
@Override