Results 1 to 2 of 2

Thread: QTcpSocket slows down in receiving after several minutes

  1. #1
    Join Date
    Jul 2008
    Location
    Philippines
    Posts
    60
    Thanks
    9
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Question QTcpSocket slows down in receiving after several minutes

    hi,

    i have a created two applications, e.i, client and server applications. I have noticed in my client app that after several minutes it slows down in receiving files. The server has already sent or written the data in the socket but my client app doesnt receive it immediately, i should wait about 10 -20 seconds before the data is received.

    here is my code under socketReadyRead function in client side:

    Qt Code:
    1. QDataStream in(clientSocket);
    2. in.setVersion(QDataStream::Qt_4_4);
    3. if (blockSize == 0) {
    4. if (clientSocket->bytesAvailable() < (int)sizeof(quint32))
    5. return;
    6. in >> blockSize;
    7. }
    8.  
    9. if (clientSocket->bytesAvailable() < blockSize)
    10. return;
    11.  
    12. QByteArray bytedata;
    13. in >> bytedata; // get the data
    14.  
    15. QString fileName;
    16. in >> fileName; // get the filename
    17. QStringList f = fileName.split("<hermz>");
    18. QString ipDir = f[0]; // get the receiver branch ip
    19. fileName = f[1]; // get the actual filename
    20. QString WRITEPATH = sOutPath + "/" + ipDir + "/" + fileName;
    21.  
    22. QDir dir;
    23. if(!dir.exists(sOutPath + "/" + ipDir))
    24. dir.mkdir(sOutPath + "/" + ipDir);
    25.  
    26. QFile fWrite(WRITEPATH);
    27. if (fWrite.open(QIODevice::WriteOnly )){
    28. fWrite.write(bytedata);
    29. fWrite.close();
    30. }
    31. logToMonitor( fileName + " received", "blue", 2);
    32.  
    33. blockSize = 0;
    To copy to clipboard, switch view to plain text mode 

    please help, thnks...

  2. #2
    Join Date
    Nov 2006
    Posts
    5
    Thanked 2 Times in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QTcpSocket slows down in receiving after several minutes

    Hi,

    set the size of the file before you write data to it.
    This has to advantages:
    1. You check immediately if you have enough space on your disk
    2. The transfer speed remains constant because it must not resize the file while receiving.

    Hope that helps.

Similar Threads

  1. QTcpSocket + receiving data
    By navi1084 in forum Qt Programming
    Replies: 1
    Last Post: 2nd June 2009, 09:10

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.