title: How to stop reading from socket
body: <p>I'm so lost.  I can't figure out how to stop reading from the server.  I'm basically sending a list of every file in the directory from the server to the client.  Heres what I'm doing.</p>
  
  <p>SERVER SIDE:</p>
  
  <pre><code> struct dirent *ep = readdir(dp);      
      while( ep ){  
          sprintf(buf, "%s", (ep-&gt;d_name));
          n = write(newsock, buf, MAX );           
          ep = readdir(dp);  
      }
  </code></pre>
  
  <p>CLIENT SIDE:</p>
  
  <pre><code>while( n = read(sock, buf, MAX)){
      printf("buf: %s\n" , buf);       
  }   
  </code></pre>
  
  <p>So the server side stuff works fine.  I can see I'm sending all the file names right, but on the client side it reads all the names but just sits waiting to read more.</p>