I finally have the time and a work related need to look at POE again.
-Though I'm doing so with half an eye toward a presentation for our local
perl mongers group.

I figured I'd start by whipping up a simple echo server via
POE::Component::Server::TCP and client via POE::Component::Client::TCP. Then
start peeling back the layers to see and document how it all works.

My echo server appears to work fine. At least when I change the port to 23
and connect to it using the standard MS Windows Telnet client. The echo
client however fails to connect. It errs out with the message:

  Client 2 got connect error 10022 (Unknown error)


Which according to the POE ML archives, might have something to do less than
optimal support for non-blocking io with Win32 Sockets:
http://www.mail-archive.com/cgi-bin/htsearch?method=and&format=short&config=
poe_perl_org&restrict=&exclude=&words=10022

I am using WinNT 4.0 sp6a, ActiveState Perl 5.6.1 build 633, and POE 0.2302.


I can see from ActiveStates changelog
(http://aspn.activestate.com//ASPN/Perl/Products/ActivePerl/Changes.html#bui
ld%20633%20monday,%20june%2017,%202002) that non-blocking io has been fixed
for waitpid... but the 2 activestate bugs
(http://www.mail-archive.com/poe@;perl.org/msg00511.html) do not appear to be
closed.

Any suggestions on how to work around this? Or what I'm doing wrong?


The code from my echo server and client follows.

# Echo Server
use strict;
use warnings;
use POE qw(Component::Server::TCP);
use constant PORT => 12321;

POE::Component::Server::TCP->new(
    Alias       => 'echo_server',
    Port        => PORT,
    ClientConnected => sub {
        print "CONNECT: [$_[HEAP]->{remote_ip}]\n";
        $_[HEAP]->{client}->put("Hello $_[HEAP]->{remote_ip}");
    },
    ClientInput => sub {
        print "[$_[HEAP]->{remote_ip}]: $_[ARG0]\n";
        $_[HEAP]->{client}->put($_[ARG0]);
    },
    ClientDisconnected => sub {
        print "DISCONNECT: [$_[HEAP]->{remote_ip}]\n";
    },
);

$poe_kernel->run();
exit 0;
1;
__END__


# Echo Client
use strict;
use warnings;
use POE qw(Component::Client::TCP);
use constant PORT => 12321;
use constant ADDR => '127.0.0.1';

POE::Component::Client::TCP->new(
    RemoteAddress => ADDR,
    RemotePort    => PORT,
    ServerInput   => sub { print "client received: $_[ARG0]\n"; },
    Connected     => sub {
        $_[HEAP]->{server}->put('hello world');
        $_[KERNEL]->yield('shutdown');
    },
);

$poe_kernel->run();
exit 0;
1;
__END__


--
Garrett Goebel
IS Development Specialist

ScriptPro                   Direct: 913.403.5261
5828 Reeds Road               Main: 913.384.1008
Mission, KS 66202              Fax: 913.384.2180
www.scriptpro.com          [EMAIL PROTECTED]

Reply via email to