http request - resend after TCP failure
-
Hi,
I send many http request from my app... Could any of you give me some pointers how save request which one are not send.... and try resend when TCP will go back to work ?
Whether there is a any functionality to realize my problem in qt in simple way ? or I should save request (to file or QQueue<QByteArray> ?) when 404 erorr recive ?
I would be really grateful for any ideas... -
Hi,
That's up to you. From the looks of it, you seem to need to build a queue of requests or at least their components. Then when a request should be processed, extract that component, create and send the request and then keep a hash with the component associated to the reply object. If there's a failure, put the component back in the queue otherwise, clean things up.
Note that you must also consider the number of failures and maybe stop at some point.
-
@SGaist Any example how save QQueue to Qfile, and read QQueue from Qfile ? I need save not processed request , in the event of a device restart...
-
First define how you are going to save your data. Will it be only text ? Will it contain binary data ? If the latter, why ?
You can then implement QDataStream operators for your structure. The rest is handle automatically.
-
@SGaist said in http request - resend after TCP failure:
First define how you are going to save your data. Will it be only text ? Will it contain binary data ? If the latter, why ?
You can then implement QDataStream operators for your structure. The rest is handle automatically.I thinking saving my not processed request to text file, on example like below:
QByteArray test1 = "http://localhost:1234/v1/test"; QByteArray test2 = "http://localhost:1234/v1/test/testDevices"; QByteArray test3 = "http://localhost:1234/info"; QQueue<QByteArray> queue; queue.enqueue(test1); queue.enqueue(test2); queue.enqueue(test3); QFile file("C:\\Test\\test.txt"); if(!file.open(QFile::WriteOnly | QFile::Text)){ return; } QTextStream out(&file); while (!queue.isEmpty()) { out << queue.dequeue(); } file.flush(); file.close();is any better way ?
-
@SGaist said in http request - resend after TCP failure:
First define how you are going to save your data. Will it be only text ? Will it contain binary data ? If the latter, why ?
You can then implement QDataStream operators for your structure. The rest is handle automatically.I thinking saving my not processed request to text file, on example like below:
QByteArray test1 = "http://localhost:1234/v1/test"; QByteArray test2 = "http://localhost:1234/v1/test/testDevices"; QByteArray test3 = "http://localhost:1234/info"; QQueue<QByteArray> queue; queue.enqueue(test1); queue.enqueue(test2); queue.enqueue(test3); QFile file("C:\\Test\\test.txt"); if(!file.open(QFile::WriteOnly | QFile::Text)){ return; } QTextStream out(&file); while (!queue.isEmpty()) { out << queue.dequeue(); } file.flush(); file.close();is any better way ?
@Damian7546
Unless (a) you really intend to restart failed http requests on restarting your application at a later time, which seems odd to me, or (b) you have a large number of requests with large data content , why would you want to save to external storage, why not just keep the queue in session memory?