Hello all,

This is my first post on here. QtCentre and forum are a great source of information.

I have read through the forum and I found somewhat related posts, but not quite on the money, so I thought I'd give this a go, hoping I haven't missed any existing information on the subject.
As I state in the description, I’m having a problem with sending multiple network requests via the QnetworkAccessManager(QNAM) post method. The windows application runs as a QApplication.

The entire application consists of a client and a server, communicating through Http requests made by the client. The server only responds to requests and doesn't take any 'initiative'.

Qt Code:
  1. Sync::Sync(ConnectionInfo info) //info contains ip address and user auth
  2. {
  3. p = new SyncPrivate;
  4. p->mManager = new QNetworkAccessManager(this);
  5. connect(p->mManager, SIGNAL(authenticationRequired(QNetworkReply*,QAuthenticator*)),
  6. SLOT(authenticate(QNetworkReply*, QAuthenticator*)));
  7. p->mIpAddress = info.remoteIP();
  8. switch(info.userLevel()) {
  9. //UserAuth info here
  10. }
  11. p->mPassword = info.password();
  12. }
  13.  
  14. void ControllerListEntry::on_actionStop_Monitoring_All_Nodes_triggered()
  15. {
  16. if (mSync != 0)
  17. return;
  18.  
  19. mSync = new Sync(mController->connectionInfo());
  20. connect(mSync, SIGNAL(finished()), this, SLOT(stopMonitoringAllNodesFinished()));
  21. foreach(Node *mNode, mController->getNodes()){ //Looping through all nodes
  22. if(!mSync->setMonitoring(mNode, false))
  23. break;
  24. }
  25. }
  26.  
  27.  
  28. void ControllerListEntry::on_actionStart_Monitoring_All_Nodes_triggered()
  29. {
  30. if (mSync != 0)
  31. return;
  32.  
  33. mSync = new Sync(mController->connectionInfo());
  34. connect(mSync, SIGNAL(finished()), this, SLOT(startMonitoringAllNodesFinished()));
  35. foreach(Node *mNode, mController->getNodes()){ //Looping through all nodes
  36. if(!mSync->setMonitoring(mNode, true))
  37. break;
  38. }
  39. }
  40.  
  41.  
  42. //For each iteration of the previous loop, the following method is called:
  43. bool Sync::setMonitoring(Node n, bool enabled)
  44. {
  45. QNetworkRequest req(QUrl("http://" + p->mIpAddress + "/rpc/set-monitoring"));
  46. req.setAttribute(QNetworkRequest::HttpPipeliningAllowedAttribute, QVariant(true));
  47. QByteArray postReq = "nodename=" + encode(n->getName());
  48. postReq += "&monitoring=" + QByteArray(enabled ? "true" : "false");
  49. p->mBusy = true;
  50. p->mReply = p->mManager->post(req, postReq);
  51.  
  52. connect(p->mReply, SIGNAL(finished()), SLOT(replyFinished()));
  53.  
  54. return true;
  55. }
  56.  
  57. //For completeness sake
  58. void Sync::replyFinished()
  59. {
  60. p->mReply->deleteLater();
  61. p->mBusy = false;
  62.  
  63. // Check for errors.
  64. if (p->mReply->error() != QNetworkReply::NoError) {
  65. emit error(p->mReply->errorString()); //will call slot showing error message
  66. return;
  67. }
  68.  
  69. emit finished(); //ControllerListEntry will do some ui stuff
  70. }
To copy to clipboard, switch view to plain text mode 

The problem is that requests are sent for only part of the Nodes in the Controller when above a certain number of Nodes. This certain number is somewhere around 8, this sound a bit vague and it is, but that's the nature of this problem. Sometimes 6 requests are sent, sometimes up to 11. Always more than 6 though.

I'm aware of the following line from the Qt Documentation for QNetworkAccessManager:
Note: QNetworkAccessManagerqueues the requests it receives. The number of requests executed in parallel is dependent on the protocol. Currently, for the HTTP protocol on desktop platforms, 6 requests are executed in parallel for one host/port combination.

That makes me expect that all the requests will be sent in blocks of 6, until no requests are left. Am I wrong in this?
Allowing HTTP Pipelining or disabling it doesn't seem to make any difference in the result.

Sometimes I get the following in the application output: QCoreApplication::postEvent: Unexpected null receiver. Would this happen when not receiving a network reply?

I can confirm:
• The setMonitoring code finished every time for every Node.
• Only for part of the (1 - very small amount) Nodes a reply is caught by the replyFinished Slot
â—‹ Using Wireshark:
§ Http Replies are actually seen on the network
§ Not always an Http reply for every request
• It is always the requests for the last n Nodes that don't get sent. No "gaps" in between.
• Qt version: Qt 4.7.4.

For 18 Nodes this is what happens on the network on Http level between client and server.
WiresharkSetMon.jpg

I hope someone can provide some ideas on the matter.

Many thanks in advance,


Tim