title: QTcpSocket: Server response delay after hours of communication
body: <p>I know some similar questions may have been asked already, but the answers to those I found did not solve my problem.</p>
  
  <p>I am runnning a QTcpSocket to recieve data over network from a client. The client asks for measurement values all 50ms and server responds. The respons from server comes right away.
  After running of 4h, the response from server comes with a delay of about 400ms and after days it is delayed for several seconds.
  When i restart the server, the response comes right away again. When the delay is there and i restart the client and connect again to the socket, the same delay is there.</p>
  
  <p>I do not know any buffer i can clear or something like this, since i do read the sended data, which should clear the buffer. Has anyone an idea, what causes this delay?</p>
  
  <p>On server i read: </p>
  
  <pre><code>    QTcpSocket* clientConnection = qobject_cast&lt;QTcpSocket*&gt;(sender());
      QString data="";
  
      if (clientConnection-&gt;bytesAvailable() &lt; (int)sizeof(quint16))
          return;
  
      QByteArray tmp=clientConnection-&gt;readAll();
  
  //  Also tried:
  //  QByteArray tmp;
  //  while (clientConnection-&gt;bytesAvailable())
  //      tmp.append(clientConnection-&gt;readAll());
  
  
      for(int i=0;i&lt;tmp.size();i++)           
          data += tmp.at(i);
  </code></pre>
  
  <p>In data is asked for a value, i read that value, write it in data and answer with:</p>
  
  <pre><code>    QByteArray block;
      if(!data.endsWith("\n"))
          data = data+"\n";
      block=data.toLatin1();
      clientConnection-&gt;write(block);
  </code></pre>
  
  <p>On client side i read the answer:</p>
  
  <pre><code>    if (tcpSocket-&gt;bytesAvailable() &lt; (int)sizeof(quint16))
         return;
  
      QByteArray tmp;
      while(tcpSocket-&gt;bytesAvailable())
          tmp.append(tcpSocket-&gt;readAll()); 
  
      for(int i=0;i&lt;tmp.size();i++)               
          data += tmp.at(i);
  </code></pre>
  
  <p>and ask again:</p>
  
  <pre><code>    block = command.toLatin1();
      if(socket)
      {
  //      Already tried this:
  //      socket-&gt;write(block,block.size());
  //      socket-&gt;flush();
  //      socket-&gt;waitForReadyRead(30000);
  
          socket-&gt;write(block);
      }
  </code></pre>
  
  <p>I already tryed with 
  clientConnection->setSocketOption(QAbstractSocket::LowDelayOption, 1);  //Disable Nagle Algorithm</p>
  
  <p>But nothing works. 
  Anyone got an idea, what the problem is here?
  Any tips are welcome. Thanks!</p>