>From the P:C:S:TCP docs, it looks like you should be able to do this by passing a reference to it via ClientArgs constructor argument. You may need to end up weakening it in client, to allow the server sessions and anything else the client heap is referring to to be reaped.
Mark. 2009/5/26 Olivier Mengué <[email protected]>: > Hi, > > I'm using POE for 3 months now with great pleasure. Thanks to all the > developers! > > I'm now playing with TCP client and server. > I've created a POE::Component::Server::TCP which has global state stored in > its HEAP, initialized in the Started event. > > How can I get access to that HEAP from the Client* events (ClientConnected > in particular) as those are called from a different session ? > Maybe there is a parent-child relationship between the sessions I could use > to retrieve the server session and call it's ->get_heap() ?. > > Below is some sample code that I'm sure you'll help me to complete. > > Olivier > dolmen on cpan.org > > > #!/usr/bin/perl > > use strict; > use warnings; > use Test::More tests => 8; > > use POE qw(Component::Server::TCP Component::Client::TCP); > > > my $host = 'localhost'; > my $port = 12344; > > POE::Component::Server::TCP->new( > Alias => "server", > Address => $host, > Port => $port, > Started => sub { > pass "[Server] Started #".$_[SESSION]->ID; > $_[HEAP]{test} = 42; > }, > ClientConnected => sub { > pass "[Server] ClientConnected #".$_[SESSION]->ID; > # How to get access to {test} from the server session's HEAP ? > #is(???, 42, "Server HEAP access"); > }, > ClientInput => sub { > pass "[Server] ClientInput #".$_[SESSION]->ID; > diag($_[ARG0]); > }, > ClientDisconnected => sub { > pass "[Server] ClientDisconnected #".$_[SESSION]->ID; > $poe_kernel->post('server', 'shutdown'); > }, > ); > > POE::Component::Client::TCP->new( > Alias => "client", > RemoteAddress => $host, > RemotePort => $port, > Started => sub { > pass "[Client] Started"; > }, > Connected => sub { > pass "[Client] Connected"; > $_[HEAP]{server}->put("Hello"); > $poe_kernel->yield('shutdown'); > }, > ServerInput => sub { }, > Disconnected => sub { > pass "[Client] Disconnected"; > }, > ); > > $poe_kernel->run; > > pass 'Stopped'; >
