Problem with socket
Thomas Hervé
therve at neocles.com
Thu Apr 29 09:58:38 EDT 2004
Grant Edwards wrote:
> On 2004-04-28, Thomas Hervé <therve at neocles.com> wrote:
>
>
>>Ok I hope it's clear. My problem is that "select" only tests
>>if there's data on the socket, and not the state of the
>>socket.
>
> That's not true. If the socket is closed, it will return from
> select as readable.
Exact.
>>I want to be able to know if socket is "alive" or something
>>like that. But I don't want to make "send" in the client (stay
>>passive). Then, if I know that my socket is closed or my link
>>down, I can try to reconnect periodically.
>
> You'll know if the socket is closed because select will mark it
> as readable, and you'll get 0 bytes when you read it.
It seems that it's not true : when I read it I have a "Connection reset
by peer" error.
> If you want to know if the network or the other host has "gone
> away", set the SO_KEEPALIVE option on the socket. That will
> generate an error if the link is down. IIRC, it takes 75
> minutes (or is it 150?) to time out after the other end goes
> away.
Yes, I've seen this option, but the delay is a bit too large (2 hours ?
depending on OS it seems) and not configurable. So I made it by send
some hearbeat regulary, even if I didn't want to I haven't found another
way. And it's better for server side, from which I can make some recv
that make the break found earlier.
--
Thomas Herve
More information about the Python-list
mailing list