Results 1 to 5 of 5

Thread: (Solved) QNetworkAccessManager and http-stream without headers

  1. #1
    Join Date
    May 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Question (Solved) QNetworkAccessManager and http-stream without headers

    Hello Folks,

    I'am using QT version 4.6.3 under debian 6.0.3. (Compiling using qmake and make, gcc version 4.4.5 (Debian 4.4.5-8))

    To read from a measuring system a data stream using http and some additional data from html-pages i tried to use QNetworkAccessManager via GET (QNetworkRequest) and QNetworkReply.

    This runs flawless with the html-Pages.

    Qt Code:
    1. reply = qnam.get(QNetworkRequest(url));
    2. connect(reply, SIGNAL(error(QNetworkReply::NetworkError)),
    3. this, SLOT(httpError(QNetworkReply::NetworkError)));
    4. connect(reply, SIGNAL(readyRead()),
    5. this, SLOT(httpReadyRead()));
    6. connect(reply, SIGNAL(finished()),
    7. this, SLOT(httpFinished()));
    To copy to clipboard, switch view to plain text mode 

    Trying to read the stream the readyRead-routine will not run. To figure out what happened I also connected the error-routine. The reported error is error #2: RemoteHostClosedError.

    However, WGET can read and save the stream:
    Qt Code:
    1. wget -S HOST:PORT
    2. --2012-04-27 13:36:46-- HOST:PORT
    3. Trying to connec to HOST:PORT... connected.
    4. HTTP-Request sent, waiting for reply...200 No Headers, assuming HTTP/0.9.
    5. Length: not specified
    6. Saving to »index.html«
    To copy to clipboard, switch view to plain text mode 

    Firefox also can save the stream.

    A longer google-search found no appropriate answers. Only some ssl-related stuff, what does not relate to my problem, as far as I can see. What I have found in QT-Sources (4.7.0, in 4.6.0 it was not there, if it is in 4.6.3 I do not know): Inside qhttpnetworkconnectionchannel.cpp ( see arrows --> in code):

    Qt Code:
    1. case QAbstractSocket::RemoteHostClosedError:
    2. // try to reconnect/resend before sending an error.
    3. // while "Reading" the _q_disconnected() will handle this.
    4. if (state != QHttpNetworkConnectionChannel::IdleState && state != QHttpNetworkConnectionChannel::ReadingState) {
    5. if (reconnectAttempts-- > 0) {
    6. closeAndResendCurrentRequest();
    7. return;
    8. } else {
    9. errorCode = QNetworkReply::RemoteHostClosedError;
    10. }
    11. } else if (state == QHttpNetworkConnectionChannel::ReadingState) {
    12. if (!reply->d_func()->expectContent()) {
    13. // No content expected, this is a valid way to have the connection closed by the server
    14. return;
    15. }
    16. if (reply->contentLength() == -1 && !reply->d_func()->isChunked()) {
    17. --> // There was no content-length header and it's not chunked encoding,
    18. --> // so this is a valid way to have the connection closed by the server
    19. return;
    20. }
    21. // ok, we got a disconnect even though we did not expect it
    22. errorCode = QNetworkReply::RemoteHostClosedError;
    23. } else {
    24. errorCode = QNetworkReply::RemoteHostClosedError;
    25. }
    26. break;
    To copy to clipboard, switch view to plain text mode 

    Does that mean, that QNAM believes that an answer without headers and without chunking is a HostClosed situation and ends the connection itself?

    I'am at a loss at the moment, because I have developed my source code with via WGET temporarily stored data. My local webserver certainly added headers and length. Can someone give some deeper insights into QNAM, why that is happening?

    I'am working around the problem for now, wget-ing packages of the stream and feeding to my program but that is a bad hack because I loose temporal coherence on the data.

    Cheers,
    Kai
    Last edited by muehle.kai; 2nd May 2012 at 12:54. Reason: Solved

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QNetworkAccessManager and http-stream without headers

    An HTTP request was made and a non-HTTP response was received. This is a misconfigured HTTP server or not an HTTP server at all.

    If you run your wget with the "-S" option do you see any headers? What is the URL?

  3. #3
    Join Date
    May 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkAccessManager and http-stream without headers

    Hi Chris,

    Quote Originally Posted by ChrisW67 View Post
    An HTTP request was made and a non-HTTP response was received. This is a misconfigured HTTP server or not an HTTP server at all.

    If you run your wget with the "-S" option do you see any headers? What is the URL?
    The stream comes from a measuring system (running linux), which is inside it's own subnet without access to the internet. Data rate approx. 30MB/s. I have only limited access to the system. But your suggestion may be right, that there is no http server at all, and the system spits out only data at that particular port. Here is what wget -S said, translated from german :-):

    Qt Code:
    1. wget -S http://192.168.1.100:5432
    2. --2012-05-02 09:35:05-- http://192.168.1.100:5432/
    3. Trying to connect to 192.168.1.100:5432... connected.
    4. HTTP-Request sent, waiting for reply...
    5. Length: not specified
    6. Saving to »index.html«
    To copy to clipboard, switch view to plain text mode 

    What could I do to convince QNAM to read that stream without headers? If that cannot be achieved, what do you suggest to read those kind of streams?

    Cheers,
    Kai

  4. #4
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: QNetworkAccessManager and http-stream without headers

    QTcpSocket is how you would connect to an arbitrary TCP endpoint and just receive data as it is sent.

  5. The following user says thank you to ChrisW67 for this useful post:

    muehle.kai (2nd May 2012)

  6. #5
    Join Date
    May 2012
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QNetworkAccessManager and http-stream without headers

    Hello Chris,

    Quote Originally Posted by ChrisW67 View Post
    QTcpSocket is how you would connect to an arbitrary TCP endpoint and just receive data as it is sent.
    that's it. I additionally implemented a QTcpSocket and did some minor changes on the sources. Now I can read via QNetworkAccessManager (already saved of data) or directly from the stream via QTcpSocket. Thank you for the suggestion!

    Cheers,
    Kai

Similar Threads

  1. Create QNetworkRequest from QString(http headers)
    By davidpmp in forum Qt Programming
    Replies: 1
    Last Post: 9th December 2011, 22:45
  2. QNetworkAccessManager and http redirection
    By grayfox in forum Qt Programming
    Replies: 5
    Last Post: 8th July 2011, 17:24
  3. HTTP Post from QNetworkAccessManager - no data sent
    By secureboot in forum Qt Programming
    Replies: 1
    Last Post: 13th April 2011, 18:46
  4. QNetworkAccessManager Http Basic Authentication?
    By jloundy in forum Qt Programming
    Replies: 5
    Last Post: 29th December 2010, 00:19
  5. get network stream with QNetworkAccessManager
    By Remco in forum Qt Programming
    Replies: 0
    Last Post: 26th August 2010, 16:25

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.