Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Can somebody tell me how to handle with connection timeouts with Net::IRC? I've got a looping irc-client with $irc->start(); But when i get a connection timeout (ping timeout) i don't get a disconnect-event and the mainloop just loops on.. How can reconnect on such a timeout-disconnect? thanks

Replies are listed 'Best First'.
Re: Net::IRC Connection times out
by DigitalKitty (Parson) on Oct 06, 2004 at 03:54 UTC
    Hi Anonymous Monk.

    IRC servers periodically send a 'PING' to clients that haven't been active for a period of time. In order to avoid a timeout, you need to send the response it is expecting (e.g. 'PONG').

    Assuming you are reading from a socket and each line read is stored in a scalar named $input:
    if ($input =~ /^PING(.*)$/i) { print $socket "PONG $1\r\n"; }


    Hope this helps,
    ~Katie
Re: Net::IRC Connection times out
by Anonymous Monk on Oct 05, 2004 at 19:24 UTC
    the easiest way to find out is to do $irc->{_debug} = 1; (before the call to start ofcourse).

    This should print out what handler it is trying to call.

      didn't work, so i put $self->{_debug} = 1; into my sub on_connect.
      This worked fine :)

      i've got the output and the handlers called:
      >>> PRIVMSG #java :blablabla<br> Handler for 'public' called.<br>
      Then I switched off my modem at the router. My normal IRC Client had a disconnect. But the Net::IRC just runned on without any output.
      I tested the whole thing on Linux and Windows(activeperl).
      Has anyone an idea for a workaround? :)
      greets