Since version 6.d of Perl 6, you can use port 0 to ask the interpreter to find a port to bind for you:
my $socket = IO::Socket::Async.listen($SOCKET_ADDR, 0);
Run Code Online (Sandbox Code Playgroud)
However, $socket is a Supply with no information on the low-level socket it's using. What is the way of finding which port is it binding to?
当您tap使用$socket变量时,将返回一个(当前未记录的)IO::Socket::Async::ListenSocket对象。这有几个方法socket-port和socket-host它们是Promises当他们解决有正确的值即可。
我们可能可以整理一下文档来表明这一点。
范例:
my $s = IO::Socket::Async.listen("127.0.0.1",0);
my $t = $s.tap;
my $p = await $t.socket-port;
$p.say;
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
108 次 |
| 最近记录: |