An ServerSocket cannot be used to accept connections before binding.
A no-argument constructor that does not yet bind ServerSocket exists, so you can call other methods in ServerSocket before binding it using the bind method. There, one method, in particular, must be called before binding: setReuseAddress(boolean on) . This Javadok mentions:
Enabling SO_REUSEADDR before binding the socket using {@link #bind (SocketAddress)} allows you to bind the socket, although the previous connection is in a timeout state.
(You can also say that the constructors that perform the binding are just convenient methods, so you don't have to call the bind(SocketAddress) method separately.)
source share