On Tue, 21 Feb 2006 11:33:39 -0500 Rocco Caputo <[EMAIL PROTECTED]> wrote:
> > Why is this so ? Isn't the alias for TCPServ 'bambi' and isn't it > > registered ? > "bambi" is the alias of the server itself, not that of a particular > connection. Each session runs in a separate POE::Session, so each > is a different post() destination. They are not given aliases by > default, but you can register them on connection and remove them > upon disconnect, similar to the way > http://poe.perl.org/?POE_Cookbook/ Chat_Server does it. Yes, I'm already using this mechanism. But it relies on a TCP connection to register the sender's ID. I'm concerned with POE messages, not the TCP stuff. I got the following together to demonstrate this. It's just me, and most likely there's something I did not grokked so far, but I find there's an inconsistency in the alias interface. Here goes. The basic idea is that 'Alias =>' works only for the TCP Client and not the Server. So there's a Server that will receive a TCP message from 'outside'. When it receives it, it uses $_[KERNEL]->post to send a POE message to 'bambi' : POE::Component::Server::TCP->new ( ClientInput => sub { $_[KERNEL]->post("bambi", "sendRequest", $_[ARG0]); }, Now, if I create another module with a simple Session bearing the 'bambi' alias, it gets received: POE::Session->create ( inline_states => { _start => sub {$_[KERNEL]->alias_set('bambi')}, sendRequest => sub {print "Got it !\n"}, } ); But if, instead of the Session above I use a Server::TCP component in the following way, it does not work: POE::Component::Server::TCP->new ( Alias => 'bambi', InlineStates => { sendRequest => sub {print "Got it !\n"}, }, ) It works with TCP Client when the TCP Server below sends a POE message: POE::Component::Client::TCP->new ( Alias => 'lion', InlineStates => { msg => sub { print " lion got: $_[ARG0]\n"; } } ) POE::Component::Server::TCP->new ( Alias => 'bambi', ClientInput => sub { $_[KERNEL]->post("lion", "msg", $_[ARG0]); }, But the other way, the Client sending a POE message to the Server, does not work unless the Client's ID is used like this (i.e. the chat server method) : # That's the client registering the Server's ID after the server # has sent a POE message: InlineStates => { msg => sub { $_[HEAP]->{scomms} = $_[SENDER]->ID; } } # So when the Client receives data from ANOTHER server, it can # send a POE message to the 'bambi' Server using the ID it has # saved previously: ServerInput => sub { $_[KERNEL]->post($_[HEAP]->{scomms} => FWreply => $_[ARG0]); } It is not possible to simply use the 'bambi' alias defined by the Server itself. But it's possible for the Server to use the alias 'lion' defined by the Client. So far, I find this is a bit inconsistent. Why should the 'Alias => ' work with the client and not with the Server ? Would this be caused by launching all modules from a main file and some data initialized prematurely ?