This program is a very simple client/server script. It sends a array over a TCP connection and return the sum of it.

The main purpose is to show how the POE::Filter::Reference works.

This is the Server script:

#!/usr/bin/perl
use strict;

# use both POE server and the filter needed
use POE qw(Component::Server::TCP Filter::Reference);
POE::Component::Server::TCP->new(
  Alias        => "sum_server",
  Port         => 11211,
  ClientFilter => "POE::Filter::Reference",
  ClientInput  => sub {
    my ($sender, $heap, $input) = @_[SESSION, HEAP, ARG0];
    my $result = $input->[0] + $input->[1];
    $heap->{client}->put(\$result);
  },
);
$poe_kernel->run();
exit 0;

And this is the client script:

#!/usr/bin/perl -w
use strict;
use POE;
use POE::Component::Client::TCP;
use POE::Filter::Reference;
my $host   = "localhost";    # The host to test.
my $port   = 11211;
my @values = (2, 3);
POE::Component::Client::TCP->new(
  RemoteAddress => $host,
  RemotePort    => $port,
  Filter        => "POE::Filter::Reference",
  Connected     => sub {
    my $j = "teste";
    print "connected to $host:$port ...\n";
    $_[HEAP]->{server}->put(\@values);
  },
  ConnectError => sub {
    print "could not connect to $host:$port ...\n";
  },
  ServerInput => sub {

    #when the server answer the question
    my ($kernel, $heap, $input) = @_[KERNEL, HEAP, ARG0];
    print "got result from $host:$port ... YAY!\n";

    #print to screen the result
    print $$input. "\n";
  },
);
$poe_kernel->run();
exit 0;

And that's it.