Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Unsolved Why am I getting many “RemoteHostClosedError” sending a POST over HTTP?

    General and Desktop
    qt5.5 qtnetwork http qnetworkreply
    2
    2
    2219
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • A
      alex.santana last edited by

      Hello,

      I am trying to interact with a virtual reality software, NeuroVR. This software has a HTTP server and the user can send data through it. The server can be accessed by the localhost:8888. If access over a browser, there is a form to submit data. The type of data is a connector name and a connector value. So, I created a Qt5.5 console program to send data for the NeuroVR.

      My problem: I am sending data each 4 seconds (more or less) and I am getting many "RemoteHostClosedError" as reply. In some cases I had sucess with an "HttpStatusCodeAttribute" equal 200, but the rate of success sometimes is less than 50%.

      I thought that the problem was the server. So I made tests over the browser accessing the localhost:8888 sending data each 1(max of 2) secs. The server accepted all, it was perfect.
      My program is based on this tutorial: Sending a HTTP request using Qt 5 framework

      My QNetworkAccessManager and QNetworkRequest are attributes of the class. They are allocated at the constructor.

      this->request = new QNetworkRequest(QUrl(this->nvrhost));
      request->setHeader(QNetworkRequest::ContentTypeHeader,"application/x-www-form-urlencoded");
      this->manager = new QNetworkAccessManager(this);
      connect(this->manager,SIGNAL(finished(QNetworkReply*)),this,SLOT(replyNVR(QNetworkReply*)));
      this->evLoop = new QEventLoop(this);
      connect(this->manager,SIGNAL(finished(QNetworkReply*)),this->evLoop,SLOT(quit()));

      This method sends the request to the server:

      void BciSocket::sendToNvr(QString data, QString connector)
      {
      QUrlQuery query;
      query.addQueryItem("connectorID",connector);
      query.addQueryItem("connectorValue",data);
      this->manager->post((*request),query.toString(QUrl::FullyEncoded).toUtf8());
      this->evLoop->exec();
      }

      My question: Why this is happening and how to can I avoid it? How to can I improve it?

      Thanks for your attention!

      1 Reply Last reply Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        Hi,

        Why are you creating your request on the heap rather than stack ?

        Also, you never delete the request so you might be covering one with another and you have a memory leak.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        1 Reply Last reply Reply Quote 0
        • First post
          Last post