Im using 2 TCP Connections, one to IRC and one to a gameserver. I want to be able to send messages between the two. On like 200 you can see how im trying to send data in one of the IRC subs to the TCP server but when doing this i get the error; Can't call method "put" on an undefined value at poe2 line 204 $_[HEAP]->{server}->put("msg $nick\@TRiNiTY\:$renmsg");    # sends message to tcp server Is there an easy way to name the first connection so i can reffer to it in other subs later on? any help is appreciated
#!/usr/bin/perl #use warnings; use strict; use POE; use POE::Component::IRC; use POE::Component::Client::TCP; use POE::Filter::Stream;; ### BEGIN REMREM ### ## RenRem Settings my $renport = 4853; # The gameserver port my $renhost = 'somehost'; # Ip/hostname of the gameserver my $renpassword = 'somepass'; # admin password ## Buffering OFF! $| = 1; # Prevents buffering problems ##renrem output settings my $reout = 'off'; ### OUTPUT STARTUP MESSAGES TO CONSOLE my $botver = 'TRiNiTY build 118'; my $botver2 = 'A lightweight Renegade admin facility.'; my $startuptime = localtime; my $uptime = $startuptime; print " [$startuptime] ### TRiNiTY RenAdmin Facility. Designed by Phil + W ;-) ###\n"; print " [$startuptime] ######\n"; print " [$startuptime] $botver Starting up...\n"; print " [$startuptime] Initializing connection to RenRem server...\n"; sub renrem_on # Connetion to RenRem POE::Component::Client::TCP->new ( RemoteAddress => $renhost, RemotePort => $renport, Connected => \&on_renconnect, ServerInput => \&on_renrecieve, Disconnected => \&on_rendisconnect, ); sub on_rendisconnect{ # Attempt to reconnect when disconnected from renrem my $tsa = localtime; #my $kernel; #$_[KERNEL]->delay( reconnect => 60 ); print " [$tsa] WARNING!:Disconnection Detected, trying to re-estab +lish communication with renrem...\n"; } sub on_renconnect { my $ts = localtime; print " [$ts] Sucessfully connected to $renhost:$renport ! +...\n"; $_[HEAP]->{server}->put($renpassword); } sub on_renrecieve { my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP, ARG0 ]; my $ts = localtime; print " [$ts] $input\n"; # NOT all input is wanted, disguard any common stings which are + not needed if($input =~ /GameSpy mode active/ || $input =~ /Id Name/ || +$input =~ /Welcome to Renegade Remote Control/ || $input =~ /Score Side Ping Address/ || $input =~ /([0-9][0 +-9][0-9]\.[0-9][0-9]\.[0-9][0-9])/ || $input =~ /GDI/ || $input =~ /Nod/ || $input =~ /Gameplay in progress/ || $input + =~ /Map :/ || $input =~ /NOD :/ || $input =~ /Gameplay Pending/ || $input =~ /Time :/ || $input =~ /Fps :/ || $inpu +t =~ /Total current bandwidth usage for players/ || $input =~ / NOD / || $input =~ /\[[0-9][0-9]\:[0-9][0-9]\ +:[0-9][0-9]\W\W(Load)\W\d\d/ || $input =~ /Total current bandwidth usage for players/ || $input =~ /\[[0-9][0-9] +\:[0-9][0-9]\:[0-9][0-9]\W\W(Load)\W\d/) { # do nothing if these pattens are matched } elsif($input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W(No p +layers)/) { #Check to see if no players are in the server $kernel->post( magnet => privmsg => '#ulfserver', "Warning +: The renrem output module has been deactivated due to the server bei +ng empty at present. It can be re-enabled at a later date using the \ +!renrem \-on command." ); $reout = 'off'; } elsif($input =~ /\[[0-9][0-9]\:[0-9][0-9]\:[0-9][0-9]\W\W[^@ \ +.]/) { #otherwise output to IRC $kernel->post( magnet => privmsg => '#ulfserver', $input ) +; } else { #disguard any unmatched or unwanted patterns #$kernel->post( magnet => privmsg => '#ulfserver', $inp +ut ); } } } ######################### RENREM COMPLETED - NOW CONNECT TO IRC ###### +################################################# sub CHANNEL () { "someircchannel" } my $botver2 = 'A standalone Renegade admin facility..'; #:: IRC Settings my $ircnetwork = 'someircserver'; my $ircport = 6667; my $ircname = 'TRiNiTY-'; my $ircident = $botver; my $ircnick = 'TRiNiTY-'; my $ircmode; # Create the component that will represent an IRC network. POE::Component::IRC->new("magnet"); # Create the bot session. The new() call specifies the events the bot # knows about and the functions that will handle those events. POE::Session->new ( _start => \&bot_start, irc_001 => \&on_connect, irc_public => \&on_public, irc_msg => \&on_msg, irc_mode => \&on_mode, ); # The bot session has started. Register this bot with the "magnet" # IRC component. Select a nickname. Connect to a server. sub bot_start { my $kernel = $_[KERNEL]; my $heap = $_[HEAP]; my $session = $_[SESSION]; $kernel->post( magnet => register => "all" ); #my $nick = 'TRiNiTY-'; $kernel->post( magnet => connect => { Nick => $ircnick, Username => $ircname, Ircname => $ircident, Server => $ircnetwork, Port => $ircport, } ); } # The bot has successfully connected to a server. Join a channel. sub on_connect { $_[KERNEL]->post( magnet => join => CHANNEL ); $_[KERNEL]->post( magnet => msg => "NickServ\@services.dal.net + :IDENTIFY somepassword\r\n" ); } # Handle Private Messages to the Bot sub on_msg { my ( $kernel, $who, $where, $msg ) = @_[ KERNEL, ARG0, ARG1, ARG2 +]; my $nick = ( split /!/, $who )[0]; my $channel = $where->[0]; my $ts = localtime; print " [$ts] <$nick:$channel> $msg\n"; } # Will Handle Changes in status on the IRC channel sub on_mode { my ( $kernel, $from, $channel, $themode, $userchanged ) = @_[ KERN +EL, ARG0, ARG1, ARG2, ARG3 ]; my $fromnick = ( split /!/, $from )[0]; my $ts = localtime; print " [$ts] <$fromnick:$channel> $themode $userchanged\n"; } # The bot has received a public message. Parse it for commands, and # respond to interesting things. sub on_public { my ( $kernel, $who, $where, $msg ) = @_[ KERNEL, ARG0, ARG1, ARG2 +]; my $nick = ( split /!/, $who )[0]; my $channel = $where->[0]; my $ts = localtime; ####### Print What Was Sent to IRC to The Console ###### print " [$ts] <$nick:$channel> $msg\n"; # !Version Sent if ($msg =~ /!version/) { print " [$ts] <$channel> version request detected\n"; $kernel->post( magnet => privmsg => CHANNEL, $botver ); $kernel->post( magnet => privmsg => CHANNEL, $botver2 ); } # !broadcast Messages Sent if ($msg =~ /!broadcast/) { #retrieve the message sent my $renmsg = split(/!broadcast/, $msg); print " [$ts] <$channel> msg $nick\@TRiNiTY\: $renmsg\n"; # output + to console $kernel->post( magnet => privmsg => CHANNEL, "$nick\@TRiNiTY\: $re +nmsg\n"); #output to IRC ## HERE I WANT TO SENT THE $RENMSG FROM THE IRC CHANNEL TO THE TCP + SERVER $_[HEAP]->{server}->put("msg $nick\@TRiNiTY\: $renmsg"); # send +s message to tcp server } # !renrem sent if ($msg =~ /!renrem/) { if ($msg =~ /\-on/) { $kernel->post( magnet => privmsg => CHANNEL, "RenRem output mo +de: Activated!"); $reout = 'on'; } elsif ($msg =~ /\-off/) { $kernel->post( magnet => privmsg => CHANNEL, "RenRem output mo +de: Deactivated!"); $reout = 'off'; } elsif ($msg =~ /\-about/) { $kernel->post( magnet => privmsg => CHANNEL, "$nick: A +bout the RenRem TRiNiTY plugin \- This module allows for server messa +ges to be forwarded over the IRC chat protocol to a pool of clients a +nd provides key gameserver functionality."); } else { $kernel->post( magnet => privmsg => CHANNEL, "!renrem (usage) +< -about/-on/-off >"); } print " [$ts] RenRem output set to $reout by $nick on $channel\n" } } # Run the bot until it is done. $poe_kernel->run(); exit 0;

Edited by Chady -- added readmore tags.


In reply to POE Sending Data Between 2 simultaneous TCP connections by Anonymous Monk

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.