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
- Your syntax highlighter is wrong
- Granddad died today
- The Three Ts of Time, Thought and Typing: measuring cost on the web
- I hate telephones
- The sorry state of OpenSSL usability
- The dots do matter: how to scam a Gmail user
- My parents are Flat-Earthers
- How Hacker News stays interesting
- Project C-43: the lost origins of asymmetric crypto
- The hacker hype cycle
- The inception bar: a new phishing method
- Time is running out to catch COVID-19
- A probabilistic pub quiz for nerds
- Smear phishing: a new Android vulnerability
Tagged . All content copyright James Fisher 2016. This post is not associated with my employer. Found an error? Edit this page.