use strict; use IO::Socket; use IO::Lambda qw(:all); use IO::Lambda::Socket qw(:all); my $server = IO::Socket::INET-> new( Listen => 5, LocalPort => 10000, Blocking => 0, ReuseAddr => 1, ); die $! unless $server; lambda { context $server; accept { # socket with an incoming connection my $conn = shift; # tell the loop to accept() again again; unless ( ref($conn)) { warn "accept() error:$conn\n" unless ref($conn); return; } # now read all from the new connection context $conn; readable { my $buf; my $n = sysread( $conn, $buf, 65536); unless ( defined $n) { warn "error reading:$!\n"; } elsif ( $n == 0) { warn "connection closed\n"; } else { print $buf; again; } }} }-> wait;