joe jiang ([info]joe_jiang) wrote,
@ 2007-08-30 19:19:00
Previous Entry  Add to memories!  Tell a Friend!  Next Entry

#!/usr/bin/perl -w
use strict;

use POE;
use POE::Component::Server::TCP;

$|=1;

my %telnetclients;

# Start a TCP server. Client input will be logged to the console and
# echoed back to each client, one line at a time.

POE::Component::Server::TCP->new
( Alias => "echo_server",
Port => 23,
ClientInput => sub {
my ( $kernel, $session, $input ) = @_[ KERNEL, SESSION, ARG0 ];
my $client=$session->ID;
print "Session ", $session->ID, " got input: $inputn";
$kernel->post($_ => scatter => $input) for keys %telnetclients;
},
InlineStates => {
scatter => sub {
my ( $heap, $what ) = @_[HEAP, ARG0];
$heap->{client}->put($what);
}
},
ClientConnected => sub {
my $client = $_[SESSION]->ID;
print "Got another visitor $clientn";
$telnetclients{ $client }=1;
},
ClientDisconnected => sub {
my $client = $_[SESSION]->ID;
print "Client $client leftn";
delete $telnetclients{ $client };
},
);

# Start the server.

$poe_kernel->run();
exit 0;




Create an Account
Forgot your login or password?
Login w/ OpenID
English • Español • Deutsch • Русский…