Why do Windows sockets break after exactly 4 minutes?

Gordon McMillan gmcm at hypernet.com
Fri Mar 22 09:08:24 EST 2002


Geoffrey Talvola wrote:

> I've noticed that Windows sockets seem to close all by themselves if
> there is no activity for 4 minutes.  Does anyone know why?  Is it
> possible to control this behavior?  Just a link to some documentation
> of this behavior would be greatly appreciated.
> 
> I don't think the same thing happens on Linux, or maybe it does but the
> timeout is longer than 4 minutes there.
> 
> I've attached a set of 2 test scripts that provoke the behavior.  Start
> up server.py first, then client.py, then wait 4 minutes.

Does it help to note that if you change:

>     time.sleep(250)

to time.sleep(15), then the socket closes after 15 seconds?

Your client does a shutdown(1) after sending some data.
The shutdown(1) causes the server to fall out of the
receive loop. It then sleeps for however long specified,
sends some data and closes the socket.

In other words, the behavior is exactly what you asked
for, and Windows' socket implementation has nothing to
do with it.

-- Gordon
http://www.mcmillan-inc.com/



More information about the Python-list mailing list