The recv() call reads data from the client application. The server and client can communicate the length of data transmitted, or the server can terminate its recv() loop when the client closes its connection.

char recv_buf[BUFSIZE];
if ((numbytes = recv(sockfd, recv_buf, sizeof recv_buf, 0)) == -1) {
      perror("recv");
      goto close;
}