title: Handling partial return from recv() TCP in C
body: <p>I've been reading through <em><a href="http://beej.us/guide/bgnet/" rel="noreferrer">Beej's Guide to Network Programming</a></em> to get a handle on TCP connections. In one of the samples the client code for a simple TCP stream client looks like:</p>
  
  <pre><code>if ((numbytes = recv(sockfd, buf, MAXDATASIZE-1, 0)) == -1) {
      perror("recv");
      exit(1);
  }
  
  buf[numbytes] = '\0';
  
  printf("Client: received '%s'\n", buf);
  
  close(sockfd);
  </code></pre>
  
  <p>I've set the buffer to be smaller than the total number of bytes that I'm sending. I'm not quite sure how I can get the other bytes. Do I have to loop over <code>recv()</code> until I receive <code>'\0'</code>?</p>
  
  <p>*Note on the server side I'm also implementing his <code>sendall()</code> function, so it should actually be sending everything to the client.</p>
  
  <p>See also <em><a href="http://beej.us/guide/bgnet/output/html/multipage/clientserver.html#simpleserver" rel="noreferrer">6.1. A Simple Stream Server</a></em> in the guide.</p>