method listen

Documentation for method listen assembled from the following types:

class IO::Socket::Async

From IO::Socket::Async

(IO::Socket::Async) method listen

method listen(Str $hostInt $port --> Supply)

Creates a listening socket on the specified $host and $port, returning a Supply to which the accepted client IO::Socket::Asyncs will be emitted. This Supply should be tapped start listening for client connections. You can use $port = 0 if you want the operating system to find one for you.

To close the underlying listening socket, the Tap returned by tapping the listener should be closed.

For example, when using tap:

my $listener = IO::Socket::Async.listen('127.0.0.1'8080);
my $tap = $listener.tap({ ... });
 
# When you want to close the listener 
$tap.close;

Or when using whenever:

my $listener = IO::Socket::Async.listen('127.0.0.1'5000);
my $tap;
react {
    $tap = do whenever $listener -> $conn { ... }
}
 
# When you want to close the listener, you can still use: 
$tap.close;