title: Socket not receiving the complete stream
body: <p>I'm coding a program to send and another to receive a stream of images by sockets.  In general terms:</p>
  
  <ul>
  <li><p>On the client's side: I get the image and pre-visualize it in the client side. Then I sent it through a socket.</p></li>
  <li><p>On the server's side: I wait for the image, and then pre-visualize it.</p></li>
  </ul>
  
  <p>Here are the snippets of code related to socket:</p>
  
  <p><strong>EDITED:</strong></p>
  
  <p><strong>Client's Side</strong></p>
  
  <pre><code>unsigned int bytes = 0;
  for (int i = 0; i &lt; imgSize; i += bytes) {
      if ((bytes = send(clientSocket-&gt;getSocketDescriptor(), (char*)inputImage.data + i, imgSize - i, 0)) == 0) {
          assert(false);
      }
      std::cout &lt;&lt; "Sent: " &lt;&lt; bytes &lt;&lt; std::endl;
  }
  char notifyChar[1];
  recv(clientSocket-&gt;getSocketDescriptor(), notifyChar , 1 , 0);
  </code></pre>
  
  <p><strong>Server's Side</strong></p>
  
  <pre><code>unsigned int bytes = 0;
  for (int i = 0; i &lt; imgSize; i += bytes) {
      if ((bytes = recv(serverQuads.getSocketDescriptor(0), (char *)sockData + i, imgSize - i, 0)) == -1) {
          assert(false);
      }
      std::cout &lt;&lt; " Received: " &lt;&lt; bytes &lt;&lt; std::endl;
  }       
  
  char notifyChar[1] = { '0' };
  send(serverQuads.getSocketDescriptor(0),notifyChar , 1, 0);
  </code></pre>
  
  <p>The image size is 57600 (<code>imgSize</code> is calculated from 3 const (<code>WIDTH</code>, <code>HEIGHT</code> and <code>CHANNELS</code>)), and <code>send()</code> returns that value. But the server only receive 53504 bytes, so it returns to <code>recv()</code> but nothing happens. It keeps waiting for the other 4096 bytes endless.</p>
  
  <p>I'm a bit confused now. I read many post but can't find out the trouble. Can anybody help me?</p>
  
  <p><strong>SOLVED:</strong></p>
  
  <p>The error was out of this snippets. Another thread was reading from the socketDescriptor and waiting for exactly 4096 bytes. So, now everything it's fine.</p>