in reply to POE sharing data between sessions

You can use the session id of the first session to look it up, and then call its get_heap() method. I'm not sure this is "the" preferred way, the following code works fine to access the heap of first session from within an event handler of the second:
use strict; use POE; use POE::Wheel::SocketFactory; my $session1 = POE::Session->create( inline_states => { _start => \&start1, } ); my $session1_id = $session1->ID(); POE::Session->create( inline_states => { _start => \&start2, access_session1 => \&access, }, ); POE::Kernel->run(); sub start1 { # start something so the session doesn't go away. $_[HEAP]->{factory} = POE::Wheel::SocketFactory->new( BindPort => '88888', SocketProtocol => 'tcp', Reuse => 'on', SuccessEvent => 'event_factory_success', FailureEvent => 'event_fatal_error', ); $_[HEAP]->{"test"} = {'a'=>1,'b'=>2}; } sub start2 { #fire an event $_[KERNEL]->yield("access_session1"); } sub access { my $sess = $_[KERNEL]->alias_resolve($session1_id); my $data = $sess->get_heap()->{"test"}; foreach my $k (keys %$data){ print "$k, $data->{$k}\n"; } } __OUTPUT__ a, 1 b, 2

Replies are listed 'Best First'.
Re^2: POE sharing data between sessions
by elwarren (Priest) on May 17, 2005 at 20:35 UTC
    Ah ha. Instead of passing my sessiond id, I was passing my session alias to the alias_resolve call. Thanks, that solves one of my problems. I'm going to pass the $session1->ID onto the HEAP during create of $session2.

    Still wouldn't mind hearing about heap vs global performance/gotchas if anyone cares to shared.

    I've looked around and can't seem to find a way to list my current sessions dynamically. Ideally I was hoping for a solution more like this (completely not real code):
    foreach my $sess ( @{ $kernel->get_sessions_named('irc_bot') } ) { print $sess->get_heap()->{USERLIST}; }
    TA!