PDA

View Full Version : Transfer Huge JSON Data from Asynchronous Database Problem



olekhanchai
25th March 2013, 09:54
I was created server side program using for query database and then return result in JSON format to another client who connected to server.
This program using for lot's of people access to this database and data will be update every second.
Then I got problems about the data that return from server side it's not completed JSON data. It's has error occure when parsing JSON data.
I'm a new on TCP/IP qt programming. Why the variable baRecv are different when it's display on Debug mode and UI mode?
How can I solve this problem? and Is Asynchronous Database suitable for this situation?

Thanks for any help.

ChrisW67
26th March 2013, 07:14
You assume that non-trivial data sent in one write() is received in one block. This is rarely the case. For example at mainwindow.cpp line 47 you assume you have 10 bytes to read as a byte count in text format; you may not have 10 bytes here. Then you assume the remaining bytes are a complete payload, you may have no bytes, part of the byte count plus payload, all of a payload, or even all of a payload plus the start of another transmission (I didn't look at your server).

You need to buffer data in response to readyRead() signals until you know you have a complete protocol data unit and then decode it.

olekhanchai
27th March 2013, 04:21
I cut out 10 bytes in text format from my code.
Use global variable to buffer response data and join it together.
Then use some phase of my protocol to check end of protocol.
Everything is OK in my client side.

Is in server side has the best way to return data from query thread?