Ok, I hope I am asking this in the correct place. I have a simple IRC Client that I want to make, there are a plethora of code snippets online for this. And I have 1/2 of a working client. It connects, responds to the PING requests and can even auto reply to any commands I want it to recognize and reply to. But my problem is, I don't want a bot that idles or auto-replies. I want a basic, bare-bones client that can send messages as well as receive them. If I try to add a loop/command to send a message it stops the entire loop and waits for me to input. I tried this in C++ using a non-blocking input command and still couldn't send any information. My Main Question, do I have to open an extra socket? Simply for sending messages that I input?
#!/usr/local/bin/perl -w # irc.pl # A simple IRC robot. # Usage: perl irc.pl use strict; # We will use a raw socket to connect to the IRC server. use IO::Socket; # The server to connect to and our details. my $server = "irc.servercentral.net"; my $nick = "opti__"; my $login = "opti__"; # The channel which the bot will join. my $channel = "#contraversy"; # Connect to the IRC server. my $sock = new IO::Socket::INET(PeerAddr => $server, PeerPort => 6667, Proto => 'tcp') or die "Can't connect\n"; # Log on to the server. print $sock "NICK $nick\r\n"; print $sock "USER $login 8 * :contraIRC\r\n"; # Read lines from the server until it tells us we have connected. while (my $input = <$sock>) { # Check the numerical responses from the server. if ($input =~ /004/) { # We are now logged in. last; } elsif ($input =~ /433/) { die "Nickname is already in use."; } } # Join the channel. print $sock "JOIN $channel\r\n"; # Keep reading lines from the server. while (my $input = <$sock>) { chop $input; if ($input =~ /^PING(.*)$/i) { # We must respond to PINGs to avoid being disconnected. print $sock "PONG $1\r\n"; } else { # Print the raw line received by the bot. print "$input\n"; } }
PS if you run this and try to send a message its in the RFC format "PRIVMSG #channelornick :message here \r\n" <-- The CRLF is required also. Any help will be appreciated! Thanks!

In reply to Very Basic Perl Question about Sockets .. and IRC by Contraversy

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.