gawk Networking: UDP Examples (working version)

Gawk provides built-in networking support. The gawk manual has some examples, for basic UDP-communication at [1]. The classical sender/receiver code snippets are as follows:

# Server
     BEGIN {
       print strftime() |& "/inet/udp/8888/0/0"
       close("/inet/udp/8888/0/0")
     }
# Client
     BEGIN {
       "/inet/udp/0/localhost/8888" |& getline
       print $0
       close("/inet/udp/0/localhost/8888")
     }

Unfortunately these examples did not work on my test system under Ubuntu 13.10 Desktop 64bit and gawk v. xxxxx. Ref. [2] provided the correct description of the fields of the network strings. Using that, my working versions are:

 #! /usr/bin/gawk -f

BEGIN {
    print strftime() |& "/inet/udp/0/localhost/8888"
    close("/inet/udp/0/localhost/8888")
}

and

#! /usr/bin/gawk -f

BEGIN {
    "/inet/udp/8888/0/0" |& getline
    print $0
    close("/inet/udp/8888/0/0")
}

According to [2], the full syntax of the special file name is:

    /net-type/protocol/local-port/remote-host/remote-port

Replace “localhost” with the IP address of a remote machine, if receiver and server are not running on the same machine.

[1] http://www.gnu.org/software/gawk/manual/gawkinet/html_node/File-_002finet_002fudp.html#File-_002finet_002fudp
[2] https://www.gnu.org/software/gawk/manual/html_node/TCP_002fIP-Networking.html