Re: Combining services.

Rocco Caputo <[email protected]> Fri, 1 Feb 2013 17:43:48 -0500
Newsgroups gmane.comp.lang.perl.poe
Message-ID <[email protected]>
Don't use an asynchronous client if you don't need one.  The cookbook =
includes examples using POE::Filter::Reference by itself.

--=20
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.
>=20
> Slim client=3D>
>=20
> use IO::Socket;
> use JSON qw( encode_json );
>=20
> my $sock =3D new IO::Socket::INET (
>    PeerAddr =3D> 'localhost',
>    PeerPort =3D> '11211',
>    Proto =3D> 'tcp'
> );
> print $sock ( encode_json( { event =3D> "position", phone =3D> "12345" =
} ) .
> '[EOM]' );
> close $sock;
> exit;
>=20
> In server I parse messages with=3D>
>=20
> POE::Component::Server::TCP->new(
>    Alias        =3D> "emt_server",
>    Address      =3D> "localhost",
>    Port         =3D> 11211,
>    ClientFilter =3D> [ "POE::Filter::Line", Literal =3D> "[EOM]" ],
>=20
>    ClientConnected =3D> sub {
>        say "Client connected";
>    },
>    # Handle client requests here.
>    ClientInput =3D> sub {
>        my ( $heap, $params_json ) =3D @_[ HEAP, ARG0 ];
>        print $params_json;
>        Wrapper::emt_event( decode_json $params_json );
>    },
>=20
> 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.
>=20
> If I use ClientFilter =3D> [ "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.
>=20
> Thank you all.
>=20
>=20
> On Wed, Jan 30, 2013 at 7:29 PM, Antti Linno <[email protected]> =
wrote:
>=20
>> Thank you. You saved me from fourth standalone daemon :D
>>=20
>>=20
>> On Wed, Jan 30, 2013 at 5:09 PM, Rocco Caputo <[email protected]> =
wrote:
>>=20
>>> On Jan 30, 2013, at 09:49, Antti Linno wrote:
>>>>=20
>>>> 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.
>>>=20
>>>> Any hints, second opinion(maybe not to merge TCP and UDP), or code
>>> examples
>>>> are welcome :)
>>>=20
>>>=20
>>> 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.
>>>=20
>>> --
>>> Rocco Caputo <[email protected]>
>>>=20
>>>=20
>>>=20
>>>=20
>>>=20
>>>=20
>>=20