title: C Unix socket programming, ensuring read/write byte counts?
body: <p>I'm writing client and server programs and I'm looking for a way to ensure all bytes are read and all bytes are sent when using read() or write() to/from the sockets opened by the client/server.</p>
  
  <p>I'm assuming I'll have to use a loop to check the number of bytes returned from the read or write functions.</p>
  
  <p>Something like this probably:</p>
  
  <pre><code>#define BUFFER 20
  char buffer[BUFFER];
  
  while (I haven't read all bytes from the buffer){
         int bytesRead = read(theSocket, myWord, BUFFER);
   }
  </code></pre>
  
  <p>And how would I ensure that all the bytes I am trying to transmit using write() have been transmitted?</p>
  
  <p>Thanks for any help!</p>