IKC(3)

๐Ÿ“ฆ version 0.2402, in arch rolling

๐Ÿ’… IKC(3) โ€” POE::Component::IKC

okay so bestie, grab a snack ๐Ÿ“ because this is the manual page for POE::Component::IKC โ€” that's POE Inter-Kernel Communication, and it lives in the Perl section of your man pages (User Contributed Perl Documentation, no cap). It's basically the group chat that lets one POE kernel slide into another POE kernel's DMs. Let's get into it โœจ


๐ŸŒธ NAME ๐ŸŒธ

POE::Component::IKC โ€” POE Inter-Kernel Communication. that's it, that's the name, and honestly it's giving main character energy ๐Ÿ‘‘


โœจ SYNOPSIS โœจ

๐Ÿ–ฅ๏ธ IKC server

so like, if you want to be the one listening, you spin up a server:

use POE::Component::IKC::Server;
# create all your sessions
POE::Component::IKC::Server->spawn(
            port=>30, name=>'Server'
    ); # more options are available
$poe_kernel->run();

(yes, the comment literally says more options are available โ€” I'm just the messenger ๐Ÿซถ)

๐Ÿ“ฑ IKC client

and if you're the one connecting, client vibes:

use POE::Component::IKC::Client;

POE::Component::IKC::Client->spawn(
            host=>name,
            port=>30,
            name=>'Client',
            on_connect=>\&build);
$poe_kernel->run();

sub build
{
    # create sessions that depend on the foreign kernel.
}

๐Ÿ“ฎ Post a state on a foreign kernel

$kernel->post('IKC', 'post', "poe://Server/session/state", $ONE_arg);

๐Ÿ” The IKC is peer-to-peer.

like, fr fr โ€” the server can post to the client too, nobody's gatekeeping:

$kernel->post('IKC', 'post', 'poe://Client/session/state', $ONE_arg);

๐Ÿ“ž Call a state on a remote kernel

okay listen ๐Ÿ˜ญ call semantics are impossible, because they would cause POE to block. like, structurally cannot happen. so IKC call is a bit different โ€” it's a post, but with an extra RSVP parameter:

$kernel->post('IKC', 'call', 'poe://Server/hello/world', $ONE_arg,
              'poe:callback');

what that does is it makes the returned value of the foreign state get sent to state callback in the current session. you may want the callback to be in another session, but lowkey I don't think this is a good idea:

$kernel->post('IKC', 'call', 'poe://Server/hello/world', $ONE_arg,
              'poe:/elsewhere/hi');
๐Ÿ’ก note: if you use ->call('IKC'), it will return the number of foreign kernels the state was sent to. handy little vibe check to find out if you're still connected to a foreign kernel ๐Ÿ˜Œ

๐Ÿช„ A little magic

if a state is posted by a foreign kernel, $_[SENDER] is only valid during that state. but โ€” and this is the slay part โ€” you will be able to post back to it:

$kernel->post($_[SENDER], 'something', 'the answer is foo');

The remote caller MUST have published states for them to be callable, eh? ๐Ÿคจ

๐Ÿ“ข Publish / Subscribe

you must publish a session's interface for it to be available to remote kernels. no publishing = no access, periodt.

if you subscribe to a remote session, you may access it as if it was a local session. iconic.

first, a session publishes its interfaces:

$kernel->post('IKC', 'publish', 'session_alias',
                    [qw(state1 state2 state3 state4)], );

then a foreign kernel subscribes to it:

# Look for a session on all known foreign kernels
$kernel->post('IKC', 'subscribe', [qw(poe://*/session_alias/)]);
# Look for a session on a specific foreign kernel
$kernel->post('IKC', 'subscribe', [qw(poe://Pulse/timeserver)]);
# Make sure the session has a given state
$kernel->post('IKC', 'subscribe', [qw(poe://*/timeserver/connect)]);

after subscription, a proxy session is created that can be accessed like any old session, though ->call() acts the same as ->post() for obvious reasons:

$kernel->post('poe:/Pulse/timeserver', 'state', $arg1, $arg2...);
โš ๏ธ currently, the session alias used by post to the proxy session must be the same one as used when subscribing. and because kernels have multiple names, if you're using '*' as the kernel name when subscribing, the session alias might not be what you think it is. see "Monitor" for the deets ๐Ÿ‘€

of course, attempting to post to a proxy session before it is created will be problematic ๐Ÿ’€. to be alerted when the proxy session is created, a callback state may be specified:

$kernel->post('IKC', 'subscribe', [qw(poe://*/timeserver)],
        'timeserver_subscribed');

the callback gets called with a list of all the sessions it managed to subscribe to. check this list before continuing โ€” that's not optional, bestie. better yet, you could use the IKC monitor (see below).

one can also let POE::Component::IKC::Client->spawn deal with all the details:

POE::Component::IKC::Client->spawn(
        port=>31337, name=>$name,
        subscribe=>[qw(poe://*/timeserver)],
        on_connect=>\&create_me,
    );

'on_connect' is only called when all the subscriptions have either been accepted. if a subscription was refused, create_ikc_client will give up ๐Ÿ˜”. if multiple foreign kernels where quieried for a session (as is the case above), subscription is deemed to succeed if at least one foreign kernel accepts the subscription. so like, one yes is enough to be let in ๐ŸŒˆ

to undo things:

$kernel->post(IKC=>'retract', 'session_alias'=>[qw(states)]);

$kernel->post(IKC=>'unsubscribe', [qw(poe://Pulse/timeserver)]);

๐Ÿ‘๏ธ Monitor

say you wanted to monitor all remote kernels that connect to you:

$kernel->post(IKC=>'monitor', '*'=>{register=>'some_event'});

sub some_event
{
    my($name, $real)=@_[ARG1, ARG2];
    print "- Remote kernel ", ($real ? '' : "alias "), "$name connected\n";
}

later, you want to know when a given remote session disconnects:

$kernel->post(IKC=>'monitor', some_kernel=>{unregister=>'bye_bye'});

or maybe you think a session should clean up and leave whenever IKC does:

$kernel->post(IKC=>'monitor', '*'=>{shutdown=>'other_event'});

sub other_event
{
    # kill wheels, alarms, selects and aliases here
}

see "monitor" in POE::Component::IKC::Responder for more details ๐Ÿซถ

๐Ÿšช Shutdown

when you feel the time is right and you want to get rid of all IKC-related sessions, just do the following:

$kernel->post(IKC=>'shutdown');

and they should all disapear. at worst, some will still have registered alises, but this won't prevent the kernel from exiting. so like, worst case is cosmetic ๐Ÿ’…

๐Ÿ  The local kernel

you can post to the local kernel as if it was remote:

$kernel->post(IKC=>'post',
                "poe://$kernel->ID/session/state"=>$ONE_arg);

however, you can't currently subscribe to local sessions. I don't know how I'm going to resolve this. ๐Ÿ™ˆ (that's the docs talking, not me โ€” I'm just relaying the whole thing.)


๐Ÿฆ‹ DESCRIPTION ๐Ÿฆ‹

This is Inter-Kernel Communication for POE. It is used to get events from one POE kernel to another. that's the whole thing. events. kernel to kernel. no cap โœจ


๐ŸŒŸ SEE ALSO ๐ŸŒŸ

  • POE::Component::IKC::Responder โ€” Heart of the system ๐Ÿ’–
  • POE::Component::IKC::Server โ€” Create a process that listens for other kernels.
  • POE::Component::IKC::Client โ€” Create a process that connects to other kernels.
  • POE::Component::IKC::ClientLite โ€” Light weight IKC implementation for places you can't use POE, such as mod_perl.
  • POE::Component::IKC::Channel โ€” Handle communcation with other kernels.
  • POE::Component::IKC::Proxy โ€” Proxy session that is created when you subscribe to a remote session.
  • POE::Component::IKC::Freezer โ€” Pure-Perl serialization method.
  • POE::Component::IKC::Specifier โ€” Helper routines for parsing IKC specifiers.

๐Ÿ‘‘ AUTHOR ๐Ÿ‘‘

Philip Gwyn <perl-ikc at pied.nu> โ€” the icon who made all this happen ๐Ÿซถ


Copyright 1999-2014 by Philip Gwyn. All rights reserved.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

See <http://www.perl.com/language/misc/Artistic.html>


and that's the whole page, bestie ๐Ÿ’– mwah ๐Ÿ’‹ this was perl v5.42.0, dated 2025-12-14, filed under IKC(3) โ€” go forth and let your kernels talk to each other ๐Ÿฆ‹โœจ

๐Ÿ“ฆ where this page comes from