IO::Socket::Async::ListenSocket Reference
A tap for listening TCP sockets
What it is #
Routines #
Signatures are reproduced from the documentation, including their declared return types. A routine listed here is part of the type's published interface; whether Raku++ implements it is a separate question, answered by the examples below.
method socket-host #
method socket-host(--> Promise)
Returns Promise.
Returns a Promise that will be kept with a Str containing the address of the listening socket.
method socket-port #
method socket-port(--> Promise)
Returns Promise.
Returns a Promise that will be kept with an Int containing the port of the listening socket.
method native-descriptor #
method native-descriptor(--> Int)
Returns Int.
Returns the corresponding file descriptor (SOCKET on Windows) for the listening socket.
Examples, run three ways #
Every example below comes from the official documentation, together with the output that documentation asserts. Each was then executed by Rakudo and by Raku++ when this page was built. Where the three agree, one result is shown; where they do not, all three are — because which of them is wrong is exactly the information worth having.
3 no-output
class IO::Socket::Async::ListenSocket is Tap {}Not executed: the documentation states no expected output for this example.
my IO::Socket::Async::ListenSocket:D $server =
IO::Socket::Async.listen('127.0.0.1', 0).tap(-> $peer {
await $peer.print: "Hello. Goodbye!\r\n";
$peer.close;
});
my (Str:D $host, Int:D $port) = await $server.socket-host, $server.socket-port;
say "The rude service is listening on $host:$port for the next 10 seconds...";
await Promise.in(10).then({ $server.close });
say "I'm done now.";Not executed: the documentation states no expected output for this example.
react {
my IO::Socket::Async::ListenSocket:D $server =
do whenever IO::Socket::Async.listen('127.0.0.1', 0) -> IO::Socket::Async:D $connection {
await $connection.print: "Hello. Goodbye!\r\n";
$connection.close;
QUIT { $server.close; .rethrow }
};
# Use $server here somehow.
}Not executed: the documentation states no expected output for this example.