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

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.