public void setReuseAddress(boolean on) throws 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.