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?
As (I think) Fletch mentioned, $_[HEAP] is session-scoped storage. That is, one Session instance cannot (easily) access the heap of another. Because your TCP and IRC sessions are different, they have different heaps. You can, however, name your sessions and pass messages between them.
This change lets other sessions send messages to your TCP connection, under the name "ren".
sub on_renconnect { my $ts = localtime; print " [$ts] Sucessfully connected to $renhost:$renport !...\n"; $_[HEAP]->{server}->put($renpassword); $_[KERNEL]->alias_set("ren"); }
Your TCP session can probably post IRC commands directly to "magnet". That's because your POE::Component::IRC instance has its own session and alias. Your remaining problem is getting data back to "ren".
For this, we'll set up a custom event handler in your TCP client.
# Connetion to RenRem POE::Component::Client::TCP->new( RemoteAddress => $renhost, RemotePort => $renport, Connected => \&on_renconnect, ServerInput => \&on_renrecieve, Disconnected => \&on_rendisconnect, InlineStates => { send_data => sub { $_[HEAP]->{server}->put($_[ARG0]); }, }, );
Now, when "ren" receives a "send_data" message, it will send some data from its own $_[HEAP]->{server}. What's left is to send that "send_data" message.
## HERE I WANT TO SENT THE $RENMSG FROM THE IRC CHANNEL TO THE TCP + SERVER $kernel->post(ren => send_data => "msg $nick\@TRiNiTY\: $renmsg");
None of my code is tested, but that's the gist of it. Have fun!
-- Rocco Caputo - http://poe.perl.org/
In reply to Re: POE Sending Data Between 2 simultaneous TCP connections
by rcaputo
in thread POE Sending Data Between 2 simultaneous TCP connections
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |