gawkinet: File /inet/tcp
2.1.2.1 '/inet/tcp'
...................
Once again, always use TCP. (Use UDP when low overhead is a necessity,
and use RAW for network experimentation.) The first example is the
sender program:
# Server
BEGIN {
print strftime() |& "/inet/tcp/8888/0/0"
close("/inet/tcp/8888/0/0")
}
The receiver is very simple:
# Client
BEGIN {
"/inet/tcp/0/localhost/8888" |& getline
print $0
close("/inet/tcp/0/localhost/8888")
}
TCP guarantees that the bytes arrive at the receiving end in exactly
the same order that they were sent. No byte is lost (except for broken
connections), doubled, or out of order. Some overhead is necessary to
accomplish this, but this is the price to pay for a reliable service.
It does matter which side starts first. The sender/server has to be
started first, and it waits for the receiver to read a line.