Anonymous - 2003-11-12

Logged In: YES
user_id=189676

I discovered the same problem running tests on
rcss::net::TCPSocket. The problem occurs because when a TCP
socket is closed, it is placed in a TIME_WAIT state for approx
twice as long as the data can be on the network. See man netstat
and look for TIME_WAIT.

This is to prevent a new socket from getting messages (internal
protocol or other) related to the old socket, such as close
messages.

The only solution I can think of is if the bind fails, to check the
state of the socket's port (I don't know how to do this in a
program, but netstat -t -n will give you a start) and if it's in
TIME_WAIT, then retry after a short period.