Hi folks,
When using Netty I know I can specify local port as zero before binding and then after the bindfuture has completed I can read the actual port.
However, I need to know the ephemeral port before the server socket is bound and the system is ready to accept connections.
I can get my own ephemeral port manually before binding by opening a ServerSocket like this:
ServerSocket s = new ServerSocket(0);
int localPort = s.getLocalPort();
However I have to close that port before I can pass the result to Netty to bind the actual socket, but that means there's a race condition where something else can get the port assigned between it being closed and Netty creating its ServerSocket.
Any thoughts on how I can resolve this?