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