相关疑难解决方法(0)

Perl 6 udp socket:如何从服务器读取响应?

server-udp.pl

my $socket = IO::Socket::Async.bind-udp('localhost', 3333);
react {
    whenever $socket.Supply -> $v {
        if $v.chars > 0 {
            $v.print;
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

client-udp.pl

my $socket = IO::Socket::Async.udp();
await $socket.print-to('localhost', 3333, "\nHello, Perl 6!");
Run Code Online (Sandbox Code Playgroud)

客户端如何读取服务器响应?
也许这还没有实现?

例如在Perl 5中:

client.pl

...
my $data_send = "Test 1234567890";
$client_socket->send( $data_send )
    or die "Client error while sending: $!\n";

# read operation
$client_socket->recv( my $data_rcv , 1024 )
    or die "Client error while received: $!\n";

print "Received data: $data_rcv\n";
...
Run Code Online (Sandbox Code Playgroud)

sockets perl6

5
推荐指数
2
解决办法
431
查看次数

标签 统计

perl6 ×1

sockets ×1