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

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?
  • Comment on Re^2: How can I write tests for deamon module?

Replies are listed 'Best First'.
Re^3: How can I write tests for deamon module?
by bowei_99 (Friar) on Nov 18, 2009 at 08:22 UTC
Re^3: How can I write tests for deamon module?
by rcaputo (Chaplain) on Nov 18, 2009 at 20:02 UTC

    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