Results 1 to 5 of 5

Thread: Server Client communication compression

  1. #1
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Server Client communication compression

    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:
    Qt Code:
    1. qUncompress: Z_DATA_ERROR: Input data is corrupted
    2. qUncompress: Z_DATA_ERROR: Input data is corrupted
    3. qUncompress: Z_DATA_ERROR: Input data is corrupted
    4. qUncompress: Z_DATA_ERROR: Input data is corrupted
    5. qUncompress: Z_DATA_ERROR: Input data is corrupted
    6. qUncompress: Z_DATA_ERROR: Input data is corrupted
    7. qUncompress: Z_DATA_ERROR: Input data is corrupted
    To copy to clipboard, switch view to plain text mode 

    Server:
    Qt Code:
    1. void Server::sendXML(QString message) {
    2. QByteArray block;
    3. block.append(message);
    4. socket->write(qCompress(block));
    5. }
    To copy to clipboard, switch view to plain text mode 

    Client:
    Qt Code:
    1. void Client::readyReadSlot()
    2. {
    3. buffer.append(socket->readAll());
    4. QString result(qUncompress(buffer));
    5. }
    To copy to clipboard, switch view to plain text mode 

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

    thank u

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Server Client communication compression

    You can stop assuming that sending 100 bytes in one "message" using TCP will result in receiving 100 bytes in one "message".
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Server Client communication compression

    Ok, but I have to check, if data is complete.
    Without uncompressing I'm not able the check, if data is complete.
    Qt Code:
    1. void Client::readyReadSlot()
    2. {
    3. buffer.append(socket->readAll());
    4. QString result(qUncompress(buffer));
    5. //check result: if data is complete process it, otherwise return.
    6. }
    To copy to clipboard, switch view to plain text mode 

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Server Client communication compression

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. The following user says thank you to wysota for this useful post:

    Qiieha (28th June 2012)

  6. #5
    Join Date
    Apr 2011
    Posts
    195
    Thanks
    49
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Server Client communication compression

    Thank you for your help wysota...

Similar Threads

  1. (NETWORKING) intranet client server communication fails
    By marco.stanzani in forum Qt Programming
    Replies: 0
    Last Post: 3rd August 2011, 10:54
  2. Communication between Client Qt4 and Server in C
    By hormoz1989 in forum Qt Programming
    Replies: 3
    Last Post: 25th March 2011, 23:58
  3. server-client communication
    By sksingh73 in forum Newbie
    Replies: 2
    Last Post: 22nd June 2010, 04:15
  4. Qt-- Client Server communication problem
    By thisismyuname in forum Qt Programming
    Replies: 2
    Last Post: 8th January 2010, 02:04

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.