-
-
Save kanatohodets/04c3486cfa5db983d6dc to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use v6; | |
my $message-bus = Supply.new(); | |
sub handle-socket ($id, $sock) { | |
$message-bus.emit("* $id has connected\n"); | |
react { | |
whenever $message-bus -> $message { | |
$sock.print($message); | |
} | |
whenever $sock.chars-supply -> $bytes { | |
$message-bus.emit("$id: $bytes"); | |
LAST { | |
$message-bus.emit("* $id has disconnected\n"); | |
return; | |
} | |
} | |
} | |
} | |
my $max-id = 0; | |
say "listening on port 3005 ... "; | |
react { | |
whenever IO::Socket::Async.listen('localhost', 3005) -> $sock { | |
my $id = $max-id++; | |
start { | |
handle-socket($id, $sock); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment