Results 1 to 20 of 22

Thread: QSslSocket to much data?

Hybrid View

Previous Post Previous Post   Next Post Next Post
  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 QSslSocket to much data?

    Hi
    I developed a Client Server Application with QSslSocket. It works very fine, but if I transfer a big amount of QDataStream
    the client receives nothing. The readyReadSlot of the Client gets executed about 23 times, but in the end there is no data.

    Does somebody know, what's wrong??

    thank u
    Last edited by Qiieha; 27th January 2012 at 15:56.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QSslSocket to much data?

    You are probably using QDataStream incorrectly.
    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: QSslSocket to much data?

    Thank u...
    No i use it correctly...like fortune example....

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QSslSocket to much data?

    You mean the broken fortune example that doesn't expect to receive much data?

    Ok then, I'll be here in case you eliminate all other possibilities and come to a conclusion you are not using QDataStream correctly.
    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. #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: QSslSocket to much data?

    ok, i use it this way:

    server send-method
    Qt Code:
    1. void Server::send_xml_data(QString message) {
    2. blockSize = 0;
    3. QString out_string = message;
    4. QByteArray block;
    5. QDataStream out_stream(&block, QIODevice::WriteOnly);
    6. out_stream.setVersion(QDataStream::Qt_4_7);
    7. out_stream << (qint16)0;
    8. out_stream << out_string;
    9. out_stream.device()->seek(0);
    10. out_stream << quint16(block.size() - sizeof(quint16));
    11. socket->write(block);
    12. }
    To copy to clipboard, switch view to plain text mode 
    client-readyReadSlot-method:
    Qt Code:
    1. void Client::readyReadSlot()
    2. {
    3. qDebug() << "readyReadSlot()";
    4. QDataStream in(socket);
    5. in.setVersion(QDataStream::Qt_4_7);
    6. if (blockSize == 0) {
    7. if (socket->bytesAvailable() < (int)sizeof(quint16))
    8. return;
    9. in >> blockSize;
    10. }
    11. if (socket->bytesAvailable() < blockSize)
    12. return;
    13.  
    14. QString result;
    15. in >> result;
    16. receive(result); //process my data
    17. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,360
    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: QSslSocket to much data?

    What if blockSize > size of the socket's read buffer?
    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.


  7. #7
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSslSocket to much data?

    ... or the serialised form of the string is longer than 65536 bytes at the sending end?

  8. #8
    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: QSslSocket to much data?

    Ok , you persuaded me...but how can I work around?

    How can I enlarge the socket's read buffer?

  9. #9
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSslSocket to much data?

    How many bytes is a "big amount of QDataStream"?

  10. #10
    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: QSslSocket to much data?

    For example 133612 bytes...

  11. #11
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QSslSocket to much data?

    Firstly, your 16-bit byte count for the transmitted packet is inadequate.

    In short, don't rely on the operating system or Qt to buffer data for you, and don't assume it will turn up all at once. Since the data packet can easily fit into memory this is the usual flow of things:
    • You have a QByteArray buffer to hold unprocessed received data (as a member of the Client class)
    • In response to readyRead():
      • Add all available bytes to that buffer.
      • While the buffer contains a complete packet, process that packet and remove it from the front of the buffer.
      • Leave any unprocessed part-packet in the buffer and leave the readyRead() handler.

Similar Threads

  1. QSslSocket Problems
    By tntcoda in forum Newbie
    Replies: 2
    Last Post: 24th December 2014, 21:26
  2. QSslSocket example
    By Ratheendrans in forum Qt Programming
    Replies: 3
    Last Post: 6th July 2011, 20:51
  3. How to clear/empty data from a QSslSocket
    By scieck in forum Qt Programming
    Replies: 1
    Last Post: 7th May 2011, 23:47
  4. QSslSocket server
    By tpf80 in forum Qt Programming
    Replies: 3
    Last Post: 7th May 2009, 04:10
  5. NEED HELP!!! about qsslsocket
    By asnoka in forum Installation and Deployment
    Replies: 2
    Last Post: 12th May 2008, 15:12

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.