in reply to IO::Socket doesn't detect lost TCP connections

I'm not an expert, but I've played around with some TCP connections. I was looking at the perldocs for IO::Socket and noticed the $socket->connected method, which tests if the socket is in a connected state, and will return undef if not connected. So maybe you can test for it in your loops.

I'm sure if you dig around thry the various methods available on for a $socket you can find a workable test.


I'm not really a human, but I play one on earth. flash japh
  • Comment on Re: IO::Socket doesn't detect lost TCP connections

Replies are listed 'Best First'.
Re^2: IO::Socket doesn't detect lost TCP connections
by tjdmlhw (Acolyte) on Sep 07, 2004 at 19:22 UTC

    The $socket->connected doesn't work for detecting if a socket has been lost. It's explained in another article - $Socket->connected Not Returning False?

    Thanks for your reply, I'm still looking so any other ideas are welcome.

        No, if you look in the reply to DaveH above, you will see that I tried the sysread, syswrite, can_read, and can_write without success. The syswrite and can_write acted as if the connection was still up. It was on or before the write that I really needed notification of the dropped connection.

        The can_read showed no signs of failure, but the sysread did fail. I have modified my script to use this failure to clear the socket and try to reconnect. This works fine for the current interface, but won't be good enough when I get to a vendor that doesn't send acknowledgements back. I still believe there should be some way of checking the connection without performing a read. I just haven't found it yet.

        That's why I say I'm still looking and would be thankful if anyone knows the answer.