title: How does the read function in c knows when to stop reading from a client socket?
body: <p>I programmed a client and a server in C to test data transfer with sockets.
  Basically the server waits for a connection, accepts it and calls a <code>read()</code> function to the client file descriptor like this:</p>
  
  <pre><code>while (read(clisock_fd, client_message, 20000) &gt; 0) {
      puts(client_message);
  }
  </code></pre>
  
  <p>And in the client program, I only send one message with <code>write()</code>, like this:</p>
  
  <pre><code>write(sockfd, my_message, strlen(my_message));
  </code></pre>
  
  <p>What i can't figure out is, if the <code>write()</code> function sends 8 bytes, and the <code>read()</code> function reads them once, how does it know that it is time to stop waiting for any other messages?</p>
  
  <p>If I send 3000 bytes, for example, the read function reads 1448 bytes, then it reads the rest, and then it just knows its over and stops. How?</p>