I am working on a Qt web framework, mimicking the usage of node.js or golang. And as a side project, I am using it to write a blog program. This project started with this simple Qt http server example I found here:
Everything seemed working, I was able to render html, parse the http header, register different path handlers to handle different requests and also serve binary contents to the client, such as QImage.
However, yesterday, I wanted to implement the image uploader of my blog. And my server cannot work properly. The client side uploader code is from a jquery uploader based on ajax. it uses XMLHttpRequest to send the file. My server can capture the head of the sent file, but it can only be 64kb in size at most. From the Google Chrome developer tool, I can see that the post request is "cancelled". I am not calling socket->close() at the end of the readyRead() slot, but still the post request is cancelled.
So how should I receive the data from a QTcpSocket? right now, I put everything inside the readyRead() slot, but when there are more than one package, how should I know that all the data has been sent?
I looked at the lookback example, http://doc.qt.nokia.com/latest/network-loopback.html. but the solution there isn't fit my problem. it knows the size of the sent file in advance and only closes the socket when the received data matches that size.
There is another thing that I am worried:
Since the QTcpSocket is asynchronized, will the data come in the order of being sent? No matter how much time I spend to process each chunk of the data? Is there any timeout issues I should care?
For example, if I process the first chunk of the data for a long time, and before I finish processing it and put it into my temp buffer, the second chunk has come and invoked the readyRead() slot again and I don't spend too much time processing it, which ends up making the second chunk of data appears in front of the first chunk in side my temp buffer. Could this be possible?
Thank you so much for your answers!