Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

IRC PING Timer

by AndresSnape (Initiate)
on Feb 02, 2013 at 19:13 UTC ( #1016738=perlquestion: print w/ replies, xml ) Need Help??
AndresSnape has asked for the wisdom of the Perl Monks concerning the following question:

Hello Perl Monks, I'm looking after your wisdom on IO::Socket::INET (more exactly, IO::Socket:SSL). I am using it for IRC (yea, I know there's POE and AnyEvent for it, but I like the freedom it gives to you). And I want to code a timer that checks if the connection is timeout (ie didn't get server PING after 60 seconds or more).

The current structure is the following:

#!/usr/bin/perl use strict; use warnings; use utf8; use IO::Socket::SSL; my $server = irc.REDACTED.us my $nick = 'wiseau'; my $login = 'theroom'; my $channel = 'redacted'; my $sock = new IO::Socket::SSL( PeerAddr => $server, PeerPort => 6697, Proto => 'tcp') or die "cannot connect\n"; print $sock "NICK ".$nick."\r\n"; print $sock "USER ".$login." * * :tommy wiseau\r\n"; while (my $input = <$sock>) { if ($input =~ /004/) { last; } print $input; if ($input =~ /^PING/) { my @pong1 = split(':', $input); my $pong = $pong1[1]; print $sock "PONG ".$pong."\r\n"; } } print $sock "JOIN ".$channel."\r\n"; while (chomp(my $input = <$sock>)) { print "$input\n"; if ($input =~ /^PING(.*)$/i) { print $sock "PONG ".$1."\r\n"; } if ($input =~ /hello/) { print $sock "PRIVMSG ".$channel." :Hello World"."\r\n"; } }

The code is actually more complicated but that snippet is the representation of the barebones, with while statements for each line, etc. It prints the raw IRC socket into STDOUT, and when you "ping out" (the act of no longer being able to reply a PING from the server) it just stays that way, and IO::Socket::SSL won't know that you actually disconnected, thus keeping the programme open all the time. Is there a way to make a "last PING request" timer to make the programme self-aware about its connection status? (Tried thinking about putting it in the last while loop but it wouldn't work because when you loose your connection it'll just cease to print, but the socket will stay open).

Comment on IRC PING Timer
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1016738]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (17)
As of 2014-08-20 14:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (116 votes), past polls