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


In reply to Re^3: How can I write tests for deamon module? by rcaputo
in thread How can I write tests for deamon module? by woosley

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.