Page 1 of 2 12 LastLast
Results 1 to 20 of 22

Thread: QSslSocket to much data?

  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,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: 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,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: 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,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: 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.

  12. #12
    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 you...
    Ok, I'll try it. And how do I check whether the packet is complete? Should I ask, if there is a </xml-response>-tag in the datastream everytime?


    Added after 32 minutes:


    Now I use that way:

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

    client
    Qt Code:
    1. void Client::readyReadSlot()
    2. {
    3. qDebug() << "readyReadSlot()";
    4. buffer.append(socket->readAll());
    5. QString result(buffer);
    6. if(!result.contains("</xml-response>"))
    7. return;
    8. receive(result);
    9. }
    To copy to clipboard, switch view to plain text mode 

    Is this OK?
    Last edited by Qiieha; 30th January 2012 at 09:17.

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

    No, it's not ok. It will fail with this xml:
    xml Code:
    1. <xml-response/>
    To copy to clipboard, switch view to plain text mode 
    or this one:
    xml Code:
    1. <xml-response>
    2. <a>
    3. <b/>
    4. <xml-response>
    5. </xml-response>
    To copy to clipboard, switch view to plain text mode 

    or this one:
    xml Code:
    1. <xml-response>
    2. <a/>
    3. </xml-response>
    4. <xml-response>
    5. <a/>
    6. </xml-response>
    To copy to clipboard, switch view to plain text mode 

    If you have xml data it is best to use a solution such as QXmlStreamReader that can resume the process of parsing when more data is available.
    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.


  14. #14
    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?

    So my Buffer is instead of a QByteArray a QXmlStreamReader.
    In readyReadSlot I add the the incoming package to my reader (addData()) and
    call xml_reader.atEnd() and process the data or wait for next packet.

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

    Is there a question here somewhere or is your problem solved?
    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.


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

    Qiieha (31st January 2012)

  17. #16
    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?

    The atEnd() returns false everytime, but I will find the bug....If I solve the problem, I mark the thread as Solved....

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

    How are you using the parser?
    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.


  19. #18
    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?

    Qt Code:
    1. while(!buffer.atEnd() && !buffer.hasError()) {
    2.  
    3. QXmlStreamReader::TokenType token = buffer.readNext();
    4.  
    5. if(token == QXmlStreamReader::EndElement && buffer.name() == "xml-response") {
    6. processData(result);
    7. //stop method
    8. }
    9.  
    10. }
    To copy to clipboard, switch view to plain text mode 
    Does this solution have a good performance. And I have to save the data additional in a QByteArray, because I neet the result as a QString.

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

    Your code doesn't make sense. Please read how to use QXmlStreamReader instead of blindly writing code.
    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.


  21. #20
    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?

    Quote Originally Posted by Qiieha View Post
    ...because I neet the result as a QString.
    Exactly what is the "result" you are trying to achieve? A string representing the entire XML document, a string extracted from part of the document, a string derived from the document by some algorithm...? Ask yourself if sending an XML document is the correct approach in the first place.

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.