Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re^3: How can I write tests for deamon module?

by rcaputo (Chaplain)
on Nov 18, 2009 at 20:02 UTC ( [id://808010]=note: print w/replies, xml ) Need Help??


in reply to Re^2: How can I write tests for deamon module?
in thread How can I write tests for deamon module?

If you're using POE, you can have both a server and its client in the same program at the same time. You are not limited to one or the other. For example:

#!perl use warnings; use strict; use POE qw(Component::Server::TCP Component::Client::TCP); POE::Component::Server::TCP->new( Alias => "server", Port => 12345, ClientConnected => sub { print "server got a connection from $_[HEAP]{remote_ip}\n"; $_[HEAP]{client}->put("Smile from the server!"); }, ClientInput => sub { my $client_input = $_[ARG0]; print "server got client input: $client_input\n"; $client_input =~ tr[a-zA-Z][n-za-mN-ZA-M]; $_[HEAP]{client}->put($client_input); }, ); POE::Component::Client::TCP->new( RemoteAddress => "localhost", RemotePort => 12345, Connected => sub { print "client connected to server\n"; $_[HEAP]{server}->put("smile"); }, ServerInput => sub { my $input = $_[ARG0]; print "client received from server: $input\n"; if ($input eq "fzvyr") { # rot13(smile) $_[KERNEL]->yield("shutdown"); $_[KERNEL]->post(server => "shutdown"); } }, ); POE::Kernel->run(); exit;

The output looks something like this:

server got a connection from 127.0.0.1 client connected to server server got client input: smile client received from server: Smile from the server! client received from server: fzvyr

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://808010]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (5)
As of 2024-03-29 06:00 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found