I'm using a (Java) TCP socket to connect to a network-enabled device.
Think about the following scenario:
1) TCP socket connection successfully created
2) Network connection interrupted for a short time (I'm testing this by simply unplugging the network cable)
3) My program closes the socket.
4) The other side of the socket only responds to requests from my side; thus, the socket at the other end of the connection does not necessarily detect the broken connection
5) Network connection is reestablished
6) My program tries to open the socket again
7) -> Get a SocketException: connection refused
Why?
Because the socket at the other end thinks that the tcp connection is still open and thus refuses any other connection requests at the same port.
What happens next?
After about 5 minutes, my program is able to open the socket again, because the other end detected that the connection is not active anymore.
Question:
Is there any way to reduce the time until I'm able to reconnect again? I'm not able to make any changes on the "other" site, i.e., I can't change the tcp connection handling of my network enabled device.