Just to show you why I recommended an Async package,
here's your problem done using my own Async::Tiny.
It should be similarly short in any of the other Async packages.
#!/usr/bin/perl
use strict;
use warnings;
use Async::Tiny;
use Path::Tiny;
use constant PORT1 => 5000;
my $connID;
my $t = Async::Tiny->new;
$t->addListenCallback( PORT1, sub
{
my $sock = shift;
$t->addReadCallback($sock, \&process_message, $sock->peerhost, ++$co
+nnID);
$t->changeReadMode($sock, 'full');
});
$t->eventloop;
sub process_message
{
my ($data, $peerhost, $id) = @_;
my $filename = "rcv_${id}_$peerhost.txt";
path($filename)->spew_raw($data);
print "[save process_message] wrote $filename\n";
}
See - nice, simple, clean, short :)
Where Async::Tiny is
|