Hm, seems we need something in the lines of "Even monkey can program POE"
( http://en.wikipedia.org/wiki/Even_a_Monkey_Can_Draw_Manga )
Server:
#!/usr/bin/env perl
use Modern::Perl '2012';
use POE qw(Component::Server::TCP Filter::Reference);
POE::Component::Server::TCP->new(
Alias => "sum_server",
Port => 11211,
ClientFilter => "POE::Filter::Reference",
ClientInput => sub {
my ( $sender, $heap, $input ) = @_[ SESSION, HEAP, ARG0 ];
say $input;
},
);
$poe_kernel->run();
exit 0;
Client:
#!/usr/bin/env perl
use Modern::Perl '2012';
use IO::Socket::INET;
use POE::Filter::Reference;
use Data::Dumper;
my $socket = new IO::Socket::INET(
PeerHost => '127.0.0.1',
PeerPort => '11211',
Proto => 'tcp',
) or die "ERROR in Socket Creation : $!\n";
my $filter = POE::Filter::Reference->new();
my %result = (
task => 'Fire and forget',
status => " seems ok to me ",
);
my $output = $filter->put( [ \%result ] );
$socket->send($output);
$socket->close();
say "Theoretically sent";
==
My problem is, the server's ClientInput is never fired. So how do I send
data from point A to point B?
Greetings,
Antti
On Sat, Feb 2, 2013 at 12:43 AM, Rocco Caputo <[email protected]> wrote:
> Don't use an asynchronous client if you don't need one. The cookbook
> includes examples using POE::Filter::Reference by itself.
>
> --
> Rocco Caputo <[email protected]>
>
> On Jan 31, 2013, at 09:41, Antti Linno wrote:
>
> > Hm, as my needs for application server are very simple, I feel that POE
> TCP
> > client is too heavy, compared to IO::Socket for example.
> >
> > Slim client=>
> >
> > use IO::Socket;
> > use JSON qw( encode_json );
> >
> > my $sock = new IO::Socket::INET (
> > PeerAddr => 'localhost',
> > PeerPort => '11211',
> > Proto => 'tcp'
> > );
> > print $sock ( encode_json( { event => "position", phone => "12345" } ) .
> > '[EOM]' );
> > close $sock;
> > exit;
> >
> > In server I parse messages with=>
> >
> > POE::Component::Server::TCP->new(
> > Alias => "emt_server",
> > Address => "localhost",
> > Port => 11211,
> > ClientFilter => [ "POE::Filter::Line", Literal => "[EOM]" ],
> >
> > ClientConnected => sub {
> > say "Client connected";
> > },
> > # Handle client requests here.
> > ClientInput => sub {
> > my ( $heap, $params_json ) = @_[ HEAP, ARG0 ];
> > print $params_json;
> > Wrapper::emt_event( decode_json $params_json );
> > },
> >
> > This works. But I somehow feel that this is not elegant solution. How do
> I
> > use POE::Filter::Reference instead of Line? Tried to freeze and send, but
> > the server did not enter ClientInput event. Is there a slim and elegant
> > solution? :) Or should I use cookbook client and just kill client after
> > every request with $kernel->yield("shutdown")? Cookbook client works
> fine.
> >
> > If I use ClientFilter => [ "POE::Filter::Reference", "YAML" ], I cannot
> > trigger ClientConnected subroutine with IO::Socket :) Tried to use
> > standalone Filter::Reference->put and send it over socket, but still no
> > luck.
> >
> > Thank you all.
> >
> >
> > On Wed, Jan 30, 2013 at 7:29 PM, Antti Linno <[email protected]>
> wrote:
> >
> >> Thank you. You saved me from fourth standalone daemon :D
> >>
> >>
> >> On Wed, Jan 30, 2013 at 5:09 PM, Rocco Caputo <[email protected]>
> wrote:
> >>
> >>> On Jan 30, 2013, at 09:49, Antti Linno wrote:
> >>>>
> >>>> Or I need advice, how to merge several sungo's(
> >>>> http://poe.perl.org/?POE_Cookbook/TCP_Servers) daemons into one
> >>> package, if
> >>>> someone would be so kind. Adding UDP should be fairly similar then.
> >>>
> >>>> Any hints, second opinion(maybe not to merge TCP and UDP), or code
> >>> examples
> >>>> are welcome :)
> >>>
> >>>
> >>> I've attached a working version of your sample code. It starts two TCP
> >>> servers and a UDP service, and lets them all run at once in the same
> >>> process.
> >>>
> >>> --
> >>> Rocco Caputo <[email protected]>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>>
> >>
>
>