Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How can I write tests for deamon module?

by rcaputo (Chaplain)
on Nov 17, 2009 at 06:49 UTC ( [id://807622]=note: print w/replies, xml ) Need Help??


in reply to How can I write tests for deamon module?

Since you are using POE, you can run the daemon and test client in the same test program. Start the daemon. Start the test client. Run the tests. Shut down the client. Shut down the server.

  • Comment on Re: How can I write tests for deamon module?

Replies are listed 'Best First'.
Re^2: How can I write tests for deamon module?
by woosley (Beadle) on Nov 17, 2009 at 06:59 UTC
    Hey, can you be more specific? If I start the daemon, it just hang there for connections, how can I test it in the same program?

      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://807622]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (3)
As of 2024-04-26 00:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found