I've been having some trouble sending session references and coderefs to a foreign
kernel and i was hoping someone here would be able to give me some advice.

On my example i have two kernels: ikc_server and ikc_client. The client aplication
will start by post an event (with an argument) on the server. Then the server will
grab the argument for processing. When it finish it will postback the result to the
client session.

This works fine with proxy sender by setting an external reference
(http://search.cpan.org/~gwyn/POE-Component-IKC-0.2200/IKC/Responder.pm#PROXY_SENDER).

I want to know if it is possible to send session references of IKC Client to IKC
Server and then use that coderef to postback from the IKC Server to the Client, so
that i wont be need to set an external reference for the sending session. Something
like this:

# create postback my $postback = $_[SESSION]->postback("status"); $kernel->post( 'IKC', 'post', 'poe://Server/ServerTest/compute', { +value=>$value, postback=>$postback} );

An example would help a lot.

Thanks in advance

Here is the code

----------- ikc_server -----------

#!/var/bin/perl use warnings; use strict; use POE qw(Component::IKC::Server); use Data::Dumper::Simple; POE::Component::IKC::Server->spawn( port =>'12345', name => 'Server', ); POE::Session->create( inline_states => { _start => \&start, compute => \&compute, finish => \&finish, _stop => \&stop, }, ); print "$$: Running server...\n"; POE::Kernel->run(); print "$$: Server exited...\n"; exit(); sub start { my ($kernel) = $_[KERNEL]; my $service_name = 'ServerTest'; $kernel->alias_set($service_name); $kernel->post( IKC => publish => $service_name, ['compute'] ); return; } sub compute { my ($kernel, $arg) = @_[KERNEL, ARG0]; my $sender_id = $_[SENDER]->ID; print "\n\t sub compute ", $arg; $kernel->refcount_increment( $sender_id, 'MYREFCOUNT' ); $kernel->yield( 'finish', $arg+1, $sender_id ); return; } sub finish { my ($kernel, $arg, $sender_id ) = @_[KERNEL, ARG0, ARG1]; print "\n\t sub finish ", $arg, "\n"; $kernel->post($sender_id, 'status', $arg); $kernel->refcount_decrement( $sender_id, 'MYREFCOUNT' ); return; } sub stop { my ( $kernel ) = $_[KERNEL]; print "\n STOP \n"; $kernel->alias_remove('ServerTest'); }
----------- ikc_client -----------
#!/var/bin/perl use warnings; use strict; use POE; use POE qw(Component::IKC::Client); use Data::Dumper::Simple; POE::Component::IKC::Client->spawn( port =>'12345', name=>"Client$$", on_connect=>\&create_sessions, ); sub create_sessions { POE::Session->create( inline_states => { _start => \&start, execute => \&execute, status => \&status, _stop => \&stop, }, ); } print "$$: Running client...\n"; POE::Kernel->run(); print "$$: Client exited...\n"; exit(); sub start { my ( $kernel, $session ) = @_[ KERNEL, SESSION ]; my $service_name = 'ClientTest'; $kernel->alias_set($service_name); $kernel->post( IKC => publish => $service_name, ['status'] ); $kernel->yield( 'execute' ); return; } sub execute { my ( $kernel, $session ) = @_[ KERNEL, SESSION ]; my $value = 0; $value = $_[ARG0] unless (! defined $_[ARG0]); print "\n\t sub execute... $value"; $kernel->post( 'IKC', 'post', 'poe://Server/ServerTest/compute +', $value ); return; } sub status { my ($kernel) = $_[KERNEL]; print "\n\t sub status... ", $_[ARG0], "\n"; sleep(1); $kernel->yield('execute', $_[ARG0]); return; } sub stop { my ( $kernel ) = $_[KERNEL]; print "\n STOP \n"; $kernel->alias_remove('ClientTest'); }

In reply to POE Component IKC - Sending session references and coderefs to a foreign kernel by oscalimero

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.