OK. I added the IO watch but it gets hung up for some reason and stops receiving data and does not finish logging in. I cant seem to see where the problem is so heres the code:
#!/usr/local/bin/perl -w use strict; use Gtk2 '-init'; use Glib qw/TRUE FALSE/; use IO::Socket; #-------------------Shared Variables------------------- my $server = "irc.freenode.net"; my $nick = "simple_bot"; my $login = "simple_bot"; my $channel = "#GRRUVI"; #-------------------Main Loop------------------- my $window = Gtk2::Window->new('toplevel'); $window->signal_connect( delete_event => sub { Gtk2->main_quit; }); $window->set_default_size( 300, 200 ); my $table = Gtk2::Table->new(2, 1, FALSE); my $scroller = Gtk2::ScrolledWindow->new; my $textview = Gtk2::TextView->new; my $entry = Gtk2::Entry->new; $scroller->add($textview); $table->attach_defaults($scroller, 0, 1, 0, 1); $table->attach_defaults($entry, 0, 1, 1, 2); $window->add($table); $window->show_all; # Connect to the IRC server. my $sock = new IO::Socket::INET( PeerAddr => $server, PeerPort => 6667, Proto => 'tcp' ) or die "Can't connect\n"; Glib::IO->add_watch( fileno $sock, [qw/in hup err/], \&incoming_data, +$sock ); # Log on to the server. print $sock "NICK $nick\r\n"; print $sock "USER $login 8 * :Perl IRC Hacks Robot\r\n"; Gtk2->main; #-------------------Incoming data------------------- sub incoming_data { my ( $fd, $condition, $fh ) = @_; if ( $condition eq 'in' ) { my $input = <$fh>; chop $input; # if ( defined $data ) { # # do something useful with the text. # my $buffer = $textview->get_buffer; # $buffer->insert( $buffer->get_end_iter, $data ); # } # Check the numerical responses from the server. if ($input =~ /004/) { # We are now logged in. # Join the channel. print $sock "JOIN $channel\r\n"; } elsif ($input =~ /433/) { die "Nickname is already in use."; } elsif ($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"; } } # if ( $condition >= 'hup' or $condition >= 'err' ) { # End Of File, Hang UP, or ERRor. that means # we're finished. # stop ability to send # $entry->set_editable(0); # $entry->signal_handler_block ($send_sig); # my $buffer = $textview->get_buffer; # $buffer->insert( $buffer->get_end_iter, "Server connection +lost !!\n" ); #close socket # $fh->close; # $fh = undef; #allow for new connection #$button->set_label('Connect'); #$button->set_sensitive(1); #$button->grab_focus; #Gtk2->main_iteration while Gtk2->events_pending; # } # if ($fh) { # the file handle is still open, so return TRUE to # stay installed and be called again. # print "still connected\n"; # possibly have a "connection alive" indicator # return TRUE; # } # else { # we're finished with this job. start another one, # if there are any, and uninstall ourselves. # return FALSE; # } }

In reply to Re^3: IRC Client (non-bot) by deadpickle
in thread IRC Client (non-bot) by deadpickle

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.