develooper Front page | perl.perl6.users | Postings from February 2018

UDP Datagram API, an RFC

Timo Paulssen
February 17, 2018 16:26
UDP Datagram API, an RFC
Message ID:
Hello Perl6 users,

I've recently been made aware of a hole in our UDP support: you can't
get the source address and port of datagrams you receive, which is an
integral part of the UDP experience.

I've sketched out a piece of code to implement passing address and port
from moarvm to rakudo, but I'm not happy with the API yet. Here's a taste:

    my $do-encoding = True;
    react {
        my $socket = IO::Socket::Async.bind-udp('localhost', 3333);
        if $do-encoding {
            # set an encoding to get the data as a string
            whenever $socket.Supply(:datagrams, :enc<utf8>).head(100) {
                say "we got the text $ from
        } else {
            # or get the datagrams with Blobs containing the data
            whenever $socket.Supply(:datagrams).head(100) {
                say "the bytes in the message were $, it
came from $_.hostname():$_.port().";

The objects you get from the supply in this case are of type

In particular I'd like a better name for the named argument that turns
"datagram mode" on; maybe just change it from :datagrams to :datagram.
And perhaps the Datagram class wants to live under another namespace. We
don't support synchronous UDP sockets, though, so maybe
IO::Socket::Async is the right namespace after all.

If you want to play with the udp support, there's a moarvm branch and a
rakudo branch both named "udp_receive_hostname_port". You can also
comment on the proposal on github and follow additional commits made in
the mean time:

Thank you for your time.
  - Timo Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About