title: Socket programming read() is reading all of my writes()
body: <p>I have a client and a server. I have two read() in my client and two write() in my server code. The server sends data to the client on the first write(), the client reads and stores to a buffer but it doesn't stop reading, it keeps reading through the server's second write() because in my client i have it set up to read 255 in the stream(from my understanding). I put 255 because i don't know how long the data datasize for first write() is. How do i fix this?</p>
  
  <p>Client:</p>
  
  <pre><code>n = read(sockfd,buffer,255);
  if (n &lt; 0) 
       error("ERROR reading from socket");
        printf("%s\n",buffer);
  
   n = read(sockfd,buffer,255);
  if (n &lt; 0) 
       error("ERROR reading from socket");
        printf("%s\n",buffer);
  </code></pre>
  
  <p>Server:</p>
  
  <pre><code>  n = write(newsockfd,datasize,strlen(datasize));
  if (n &lt; 0) error("ERROR writing to socket");
  
  n = write(newsockfd,data,255);
  if (n &lt; 0) error("ERROR writing to socket");
  </code></pre>