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)