I have a part in code that checks port availability (opens connection and immediately close it) :
try{
new ServerSocket(currentConnector.getPort()).close();
}
The porblem here is that the port enters a state of TIME_WAIT which differs from system to system.
I want to make sure that after close()
the port is available.
One way I can think of is adding 60-90 seconds of sleep. But it doesn't seem very elegant.
Can I validate with Java (w/o bash/batch) that the port was released from TIME_WAIT?
Thanks!