I hear what you're saying
sub handle_connection {
my ($event) = @_;
my $socket = $event->w()->fd();
my $client = $socket->accept();
print "Someone connected $client\n";
## Set up a callback to handle each line of input...
Event->io(
fd => $client,
cb => sub { handle_input(@_) },
poll => 'r',
);
}
sub handle_input {
my ($event) = @_;
my $fd = $event->w()->fd();
if ( eof($fd) ) {
$event->w()->cancel();
return;
}
print "I heard: " . <$fd> ;
}
./example4.pl &
echo "Look out" | nc localhost 2000
Someone connected IO::Socket::INET=GLOB(0x82e6a94)
I heard: Look out
Finished