in reply to Re^3: IO::Socket reconnect
in thread IO::Socket reconnect

Of course. I tried to use same code as in your example. such code don't work for me. As I understand if I open socket to accept connections (not to create to a remote host) then it doesn't have state "connected" at all. Not sure if my suggestion is right, I'm beginner in Perl (and in programming). I checked my suggestion with this example: http://www.perlmonks.org/?node_id=884065 Script's logic is to accept a connection and start to send a data, if connection was closed, then stop to publish a data and wait for a new connection

Replies are listed 'Best First'.
Re^5: IO::Socket reconnect
by NetWallah (Canon) on Feb 18, 2016 at 04:27 UTC
    I researched this some more, and now wish to withdraw what I proposed earlier.

    The correct way to handle this is to do what golux (++) said.

    Here is the sequence of events on failure:

    * You attempt to SEND to the client
    * Client has closed the socket
    * The error is indicated to your program via a $SIG{PIPE}
    * You need to trap that signal as golux suggested, and set the value of the global $b_err
    * You check the value of $b_err before the next activity on the socket.
    * IF triggered, close the client socket, and wait for the client to reconnect (Go back to "accept").

            "Think of how stupid the average person is, and realize half of them are stupider than that." - George Carlin

      Yep, this is what I already have done =)