I have a bit of code that makes use of the ServerSocket. In order to lock down the use of the local port, I'm trying to set the SO_EXCLUSIVEADDRUSE socket option. However, ServerSocket doesn't appear to allow options to be set before calling bind(). This is because the socket is not initialized until the bind() call. DatagramSocketImpl provides an example of initializing the sockfd in the constructor, which allows for setting socket options before bind.
Is there a way to set options on a ServerSocket before bind() with the current library? Or will I need to wait for a fix?
Code: Select all
// ensure bind will provide exclusive access to port if successful
serverSocket.setOption(SOL_SOCKET, SO_EXCLUSIVEADDRUSE, TRUE);