PDA

View Full Version : Server Client communication compression



Qiieha
28th June 2012, 11:49
Hi,
I develeoped Client Server Communication with QSslSocket, The protocol of the communication is xml.
The xml strings can be very long and so I want to use compression.
I did it and it seems to work, but I get following message at the client:


qUncompress: Z_DATA_ERROR: Input data is corrupted
qUncompress: Z_DATA_ERROR: Input data is corrupted
qUncompress: Z_DATA_ERROR: Input data is corrupted
qUncompress: Z_DATA_ERROR: Input data is corrupted
qUncompress: Z_DATA_ERROR: Input data is corrupted
qUncompress: Z_DATA_ERROR: Input data is corrupted
qUncompress: Z_DATA_ERROR: Input data is corrupted


Server:


void Server::sendXML(QString message) {
QByteArray block;
block.append(message);
socket->write(qCompress(block));
}


Client:


void Client::readyReadSlot()
{
buffer.append(socket->readAll());
QString result(qUncompress(buffer));
}


It works, but what can I do against the error message.

thank u

wysota
28th June 2012, 12:04
You can stop assuming that sending 100 bytes in one "message" using TCP will result in receiving 100 bytes in one "message".

Qiieha
28th June 2012, 12:18
Ok, but I have to check, if data is complete.
Without uncompressing I'm not able the check, if data is complete.


void Client::readyReadSlot()
{
buffer.append(socket->readAll());
QString result(qUncompress(buffer));
//check result: if data is complete process it, otherwise return.
}

wysota
28th June 2012, 13:14
TCP does not know the concept of "complete" data. The protocol just sends an opaque stream of bytes over network. If you want to know if you read all the bytes you expected then you have to know what to expect in the first place. One of possible approaches is to prepend the block of data with the size of the block. Then the receiving end can read the size and learn how many more bytes it needs to read.

Qiieha
28th June 2012, 13:32
Thank you for your help wysota...;)