Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Why am I getting many “RemoteHostClosedError” sending a POST over HTTP?
Forum Updated to NodeBB v4.3 + New Features

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

Scheduled Pinned Locked Moved Unsolved General and Desktop
qt5.5qtnetworkhttpqnetworkreply
2 Posts 2 Posters 2.7k Views 1 Watching
  • 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 Offline
    A Offline
    alex.santana
    wrote on 30 Nov 2015, 14:28 last edited by
    #1

    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
    0
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 2 Dec 2015, 23:45 last edited by
      #2

      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
      0

      1/2

      30 Nov 2015, 14:28

      • Login

      • Login or register to search.
      1 out of 2
      • First post
        1/2
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved