title: Unable to read correctly from socket
body: <p>I have a server application which sends some <strong>xor encrypted strings</strong>. I am reading them from my QT client application. Sometimes, the server is slower and I am not able to receive the entire string. I have tried something like below but it gets stuck ( see the comment below). How can I wait until I have the entire data.  I tried <code>bytesAviable()</code> but then again i get stuck (infinite loop)</p>
  
  <pre><code>QTcpSocket * sock = static_cast&lt;QTcpSocket*&gt;(this-&gt;sender());
  if (key == 0)
  {
      QString recv(sock-&gt;readLine());
      key = recv.toInt();
      qDebug() &lt;&lt; "Cheia este " &lt;&lt; key;
  
      char * response = enc_dec("#AUTH|admin|admin",strlen("#AUTH|admin|admin"),key);
      sock-&gt;write(response);
  }
  else
  {
      busy = true;
      while (sock-&gt;bytesAvailable() &gt; 0)
      {
          unsigned short word;
          sock-&gt;read((char*)(&amp;word),2);
          qDebug()&lt;&lt;word;
          //Sleep(100); if i do this than it works great!
          QByteArray bts = sock-&gt;read(word);
          while (bts.length() &lt; word)
          {
              char bit; //here get's stuck
              if (sock-&gt;read(&amp;bit,1) &gt; 0)
                  bts.append(bit);
              sock-&gt;flush();
          }
  
          char * decodat = enc_dec((char*)bts.data(),bts.length() - 2,key);
          qDebug() &lt;&lt; decodat;
      }
  
  }
  </code></pre>