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:
Code:
if (blockSize == 0) {
if (clientSocket->bytesAvailable() < (int)sizeof(quint32))
return;
in >> blockSize;
}
if (clientSocket->bytesAvailable() < blockSize)
return;
in >> bytedata; // get the data
in >> fileName; // get the filename
QString ipDir
= f
[0];
// get the receiver branch ip fileName = f[1]; // get the actual filename
QString WRITEPATH
= sOutPath
+ "/" + ipDir
+ "/" + fileName;
if(!dir.exists(sOutPath + "/" + ipDir))
dir.mkdir(sOutPath + "/" + ipDir);
fWrite.write(bytedata);
fWrite.close();
}
logToMonitor( fileName + " received", "blue", 2);
blockSize = 0;
please help, thnks...:confused:
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.