use strict; use warnings; use feature qw/ say /; use utf8; use Sereal qw/ sereal_decode_with_object /; use IO::Async::Loop; use IO::Async::Listener; use Future; $, = "\t"; my $PORT = 53123; my $num = 0; my $dec = Sereal::Decoder-> new; my $loop = IO::Async::Loop-> new; my $lst = IO::Async::Listener-> new( on_stream => sub { my ( $self, $stream ) = @_; $stream-> configure( on_read => sub { 0 }); $loop-> add( $stream ); $stream-> read_until_eof-> on_ready( sub { my $F = shift; my ( $buf, $eof ) = $F-> get; print ++$num, length( $buf ), unpack( 'H*', $buf ), ''; say sereal_decode_with_object( $dec, $buf ) }) } ); $loop -> add( $lst ); $lst-> listen( addr => { family => 'inet', socktype => 'stream', ip => '127.0.0.1', port => $PORT, }, )->on_done( sub { say "Listening on $PORT..." }); $loop-> run;