What syscalls does a UDP server need?
I previously described the syscalls needed for a multi-client TCP server. There are at least eight:
close. This could be used to make an echo server: clients can open a TCP connection, and whatever bytes they send get echoed back.
Now let’s look at the simplest UDP server, and again make an echo server: clients can send a UDP datagram, and whatever they send gets echoed back.
udp_fd = socket(UDP): “OS, please create a UDP socket, and give me a file descriptor referencing it”.
bind(udp_fd, 9999): “OS, please point UDP port 9999 to the new UDP socket”.
msg, from = recvfrom(udp_fd): “OS, please put me to sleep until a UDP datagram is received, then give it to me”.
sendto(udp_fd, msg, from): “OS, please send this UDP datagram from my port to this remote address and port”.
close(udp_fd): “OS, I’m done listening for new datagrams. Stop listening on that port, and remove this file descriptor”.
Compared to the TCP server, we of course don’t get the features of TCP: messages are unreliable, unordered, and nothing monitors network congestion.
But a benefit is simplicity: we have no
accept. We do not have to manage multiple connections, deal with splitting byte streams into individual messages, or work with
The other benefit is flexibility: our communication may not fit into the TCP model very well.
More by Jim
- The inception bar: a new phishing method
- The hacker hype cycle
- Project C-43: the lost origins of asymmetric crypto
- How Hacker News stays interesting
- My parents are Flat-Earthers
- The dots do matter: how to scam a Gmail user
- The sorry state of OpenSSL usability
- I hate telephones
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- Granddad died today
- Your syntax highlighter is wrong
Tagged . All content copyright James Fisher 2016. This post is not associated with my employer. Found an error? Edit this page.