PDA

View Full Version : QTcpSocket slows down in receiving after several minutes



cutie.monkey
6th October 2009, 10:00
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:



QDataStream in(clientSocket);
in.setVersion(QDataStream::Qt_4_4);
if (blockSize == 0) {
if (clientSocket->bytesAvailable() < (int)sizeof(quint32))
return;
in >> blockSize;
}

if (clientSocket->bytesAvailable() < blockSize)
return;

QByteArray bytedata;
in >> bytedata; // get the data

QString fileName;
in >> fileName; // get the filename
QStringList f = fileName.split("<hermz>");
QString ipDir = f[0]; // get the receiver branch ip
fileName = f[1]; // get the actual filename
QString WRITEPATH = sOutPath + "/" + ipDir + "/" + fileName;

QDir dir;
if(!dir.exists(sOutPath + "/" + ipDir))
dir.mkdir(sOutPath + "/" + ipDir);

QFile fWrite(WRITEPATH);
if (fWrite.open(QIODevice::WriteOnly )){
fWrite.write(bytedata);
fWrite.close();
}
logToMonitor( fileName + " received", "blue", 2);

blockSize = 0;


please help, thnks...:confused:

Elgerton
9th December 2009, 22:14
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.