We are developing a tcp/ip client/server application and have the following
problem (SunOS 4.1.x, also observed on other UNIX os'es):
The tcp/ip communication works except for the problem below.
When our server quits, it calls close() on the socket it bind()'ed to.
When the server is restarted, it attempts to re-bind() to the same socket, but
the call returns EADDRINUSE, which means that the specified address is
already in use.
This behavior will continue for about 30-60 seconds or so after the
server has quit, at which point then the OS seems to silently recognize
that the port is free, and the bind() magically works again. I cannot seem to
cause the port to clear and bind() to succeed through any actions of my
own (except to wait!). I know this is not normal server behavior!
We are doing everything as cleanly as we can; our code is modeled closely
on the TCP/IP socket example in "Using C on the UNIX system" and I have
RTFMs to no avail.
Have other people experienced this? Can anyone help us solve this
problem, or offer any pearls of wisdom?
Thanks in advance,