how to know if socket is still connected

nephish at xit.net nephish at xit.net
Mon Jul 17 15:36:00 EDT 2006


> If the server _application_ crashes or exits, then the OS will
> close the socket and recv() will return "".  If somebody powers
> down the server without warning, or if the server OS crashes,
> or if the Ethernet cable between the Internet and the server is
> cut, then the socket will not be closed, and recv() will wait
> forever[1].

Ok, yes all of the above is what i mean. Actually I am not too
concerned about a server os crash, or the cable being cut. But I have
had them close the connection on me, after which i just reconnect
(whenever i discover that its happened)

>[1] Unless you've enabled the TCP Keepalive feature, in which
>     case the socket will timeout in a couple hours and recv()
>     will return "".

if this is something that must be enabled, or is not enabled by
default, then it is not enabled.
so i should be pretty good.

thanks for all of your help, gents !
-sk




Grant Edwards wrote:
> On 2006-07-17, nephish at xit.net <nephish at xit.net> wrote:
>
> > oh, sorry, what i mean by dropped is that the server i am
> > connecting to can close the connection.
>
> Then recv() will return "" and send() will raise an exception.
>
> > If that happens, i need to know about it. i also need to know
> > about it if the server i am connecting to just dies.
>
> Again, you have to define what you mean by "server just dies".
>
> If the server _application_ crashes or exits, then the OS will
> close the socket and recv() will return "".  If somebody powers
> down the server without warning, or if the server OS crashes,
> or if the Ethernet cable between the Internet and the server is
> cut, then the socket will not be closed, and recv() will wait
> forever[1].
>
> > if recv() returns "" is that the same as NONE ?
>
> No.  It's the empty string (also spelt '').
>
> > I mean can the value be tested true or false?
>
> Yes.  The empty string is false, all non-empty strings are
> true.
>
> [1] Unless you've enabled the TCP Keepalive feature, in which
>     case the socket will timeout in a couple hours and recv()
>     will return "".
>
> --
> Grant Edwards                   grante             Yow!  Now I am depressed...
>                                   at
>                                visi.com




More information about the Python-list mailing list