Qt Code:
  1. QFile file(filePath + "/" + fileName);
  2. file.open(QIODevice::ReadOnly);
  3. QByteArray byteArray;
  4.  
  5. while (numberOfPackages > 0){
  6. byteArray = file.read(1024);
  7. numberOfPackages--;
  8.  
  9. if(sock->state()!=QAbstractSocket::ConnectedState){
  10. printf("Socket disconnected error\n");
  11. return;
  12. }
  13.  
  14. sock->write(byteArray);
  15.  
  16.  
  17. if (sock->bytesToWrite() > 0 && !sock->waitForBytesWritten(10000)){
  18. printf("Socket write error\n");
  19. printf("socket error: %d %s, socket state: %d\n", sock->error(), sock->errorString().toAscii().data(),
  20.  
  21. sock->state());
  22. return;
  23. }
  24.  
  25. }
To copy to clipboard, switch view to plain text mode 

As I said the second if statement is executed after sending about 50KB of data.