We will take the motivating example from our last chapter, which was to provide a service that converts all text into uppercase. This is useful because you can directly compare the UDP code from here to the TCP server code from Chapter 3, An In-Depth Overview of TCP Connections.
Our server begins by setting up the socket and binding to our local address. It then waits to receive data. Once it has received a data string, it converts the string into all uppercase and sends it back.
The program flow looks as follows:
If you compare the flow of this program to the TCP server from the last chapter (Chapter 3, An In-Depth Overview of TCP Connections), you will find that it's much simpler. With TCP, we had to use
accept(). With UDP, we skip those calls and go straight into receiving data with
recvfrom(). With our TCP server...