Why do Windows sockets break after exactly 4 minutes?
Peter Hansen
peter at engcorp.com
Thu Mar 21 19:36:19 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.
Haven't run your tests, but isn't this what SO_KEEPALIVE is used for?
Try using:
import socket
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.setsockopt(socket.SOL_SOCKET, socket.SO_KEEPALIVE, 1)
and this will turn on the keep-alive feature (I think... pulled
that last line from pygale.py since I don't know where it
is well documented).
-Peter
More information about the Python-list
mailing list