I have run into a problem with a network server that receives signals from devices my company produces. The device will occasionally reuse the source port that it had just
Building on Nikolai's answer,
Socket s;
...
s.setSoLinger(true,0);
would be the equivalent in Java.
EDIT: Another thing you might like to look at would be setReuseAddress(true);
The old not-recommended trick to avoid TIME_WAIT
is to set SO_LINGER
socket option to { 1, 0 }
- the close
then sends RST
instead of doing normal flush/four-way exchange sequence, thus avoiding the TIME_WAIT
all together (be warned - you might lose tail of what you still have in the send buffer.) I can't comment on whether this could be done in Java though.
EDIT: Can you confirm with tcpdump
that the clients really reuse source port numbers? If not, this might just be the classic case for SO_REUSEADDR listening socket option as Jon pointed out.
The server is ignoring the SYN packets from the client because it cannot distinguish between those for a new session using the old source port and retransmissions from the old session. If you circumvent the TIME_WAIT
state on the server, by setting the system timer interval for aging out TIME_WAIT state entries in the control block table, then how will your server properly ignore SYN retransmissions for sessions that have already terminated?