SocketServer: Address already in use

Andrew Bennetts andrew-pythonlist at puzzling.org
Sat May 17 22:45:14 EDT 2003


On Sat, May 17, 2003 at 09:49:22PM +0200, Heiko Wundram wrote:
> On Fri, 2003-05-16 at 21:11, Thomas Guettler wrote:
> > After some minutes the socket gets released and I can restart the
> > server. How can I close the socket of the server cleanly so that I can
> > reuse the adress again at once?
> 
> You're using Linux, right? AFAIK, the socket gets released when the
> connection you made to the socket is phased out of TIME_WAIT mode by the
> kernel. You can check this by doing a netstat right after the server
> exits.
> 
> Anybody prove me wrong, but I think you can't do anything about it, save
> patch the kernel TCP/IP stack to have a smaller TIME_WAIT on sockets
> that were released when a program crashes...

You can do something about it.  From 'man 7 socket':

SOCKET OPTIONS
       ...
       SO_REUSEADDR
              Indicates  that the rules used in validating addresses supplied in
              a bind(2) call should allow reuse of local addresses. For  PF_INET
              sockets this means that a socket may bind, except when there is an
              active listening socket bound to the address. When  the  listening
              socket  is bound to INADDR_ANY with a specific port then it is not
              possible to bind to this port for any local address.

-Andrew.






More information about the Python-list mailing list