The recvfrom() call reads data from the client application. Server and client can communicate the length of data transmitted, or the server can terminate its recvfrom() loop when the client closes its connection.
if ((numbytes = recvfrom(sockfd, buf, sizeof buf, 0, (struct sockaddr *) &their_addr, &my_addr_size)) == -1) { perror("recvfrom"); goto close; }