Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

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).


In reply to IRC PING Timer by AndresSnape

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others lurking in the Monastery: (5)
As of 2024-04-20 00:31 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found