I have a simple logic Java that checks if a port is already in use or not:
public static boolean isPortInUse(int port)
{
ServerSocket socket = null;
try {
socket = new ServerSocket(port);
socket.setReuseAddress(true);
} catch (Exception e) {
return true;
}
finally
{
if (socket != null) {
try {
socket.close();
} catch (Exception e) {
return true;
}
}
}
return false;
}
I am new to socket programming so I am not able to understand what is the use of the method "setReuseAddress"
here. I have gone through this link but I am not getting clarity the purpose of it.