Results 1 to 7 of 7

Thread: How to know when HTTPmessage has finished

  1. #1
    Join Date
    May 2020
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows Android

    Default How to know when HTTPmessage has finished

    I am using the http server example as a basic data server and QAccessManager in the test client application.

    The client app contains the following code:

    1, connect(mAccessManager, SIGNAL(finished(QNetworkReply *)), this, SLOT(FinishedPost(QNetworkReply*)));

    2. if (postMsg == true)
    3. {
    4. mNetworkReply = mAccessManager->post(request, mPostMsgData);
    5. }
    6. else
    7. {
    8. mNetworkReply = mAccessManager->put(request, mPostMsgData);
    9. }

    10. if (mNetworkReply != NULL)
    11. {
    12. connect(mNetworkReply, SIGNAL(readyRead()), this, SLOT(NetworkReadyRead()));
    13. // connect(mNetworkReply, SIGNAL(finished()), this, SLOT(FinishedRead()));

    14. connect(mNetworkReply, SIGNAL(error(QNetworkReply::NetworkError)), this,
    SLOT(NetworkErrors(QNetworkReply::NetworkError)));

    I try either line 1 or line 13.

    Neither finished is triggered unless the server sends an explicit message back not just an ACK.


    In the server (httprequesthandler.cpp) I have the following code

    connect(mTcpSocket, SIGNAL(readyRead()), this, SLOT(NetworkReadyRead()));
    connect(mTcpSocket, SIGNAL(finished()), this, SLOT(FinishedRead()));
    connect(mTcpSocket, SIGNAL(disconnected()), SLOT(Disconnected()));


    FinishedRead is never called to tell me that the complete message has been received. I look at the length specified in the header and read until I get that many bytes. Several time however packets appear to be resent. I will get a complete file based on the size in the header and then I get more data sometime even the entire message all over again.

    What handshaking has to be done to tell both apps when the message transfer is complete. the test message is a 40M tiff image. Is it possible that size is a limiting factor? For what its work we are using wired network connections not wireless so it is not a signal issue.


    Bruce

  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: How to know when HTTPmessage has finished

    Please use [code]...[/code] tags around code. Easier to read, and you do not need to number lines yourself.

    Typically the client will issue a finished() signal when the server closes the connection after sending the file.

    Are you certain that you ever enter the code block at line 10?

  3. #3
    Join Date
    May 2020
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to know when HTTPmessage has finished

    Quote Originally Posted by ChrisW67 View Post
    Please use [code]...[/code] tags around code. Easier to read, and you do not need to number lines yourself.

    Typically the client will issue a finished() signal when the server closes the connection after sending the file.

    Are you certain that you ever enter the code block at line 10?
    Chris:
    Thank for the reply. Yes it is getting into that block. I followed in in with the debugger. This is a case where the client is sending data to the server to store. So in this case the server needs to know when it has received all of the data. It would be nice if the client knew when it was done sending the data as well but finished is only called in the client if the server sends back a reply. I modified the server code to track the incoming data and send a message as soon as the count is equal to what the header said then the server closes that TCP socket. Not sure if that is the right way but it does stop the redundant messages. None of the examples I could find online used the header information so I cannot tell how others are getting the end of data message. If the client knew when it was finished it could close the connection but that does not seem to the the case here.

    Bruce

  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: How to know when HTTPmessage has finished

    Server and client are somewhat arbitrary. Perhaps I should word it this way, in the simple case the receiver knows the transmission is finished when the sender closes the socket (see Fortune Server Example). At its simplest HTTP operates that way. In practice though, network socket connections are kept open and the higher level protocol tracks the start and end of transactions.
    I do not know which "http server example" you are referring to. There isn't one here. Can you provide a link?

  5. #5
    Join Date
    May 2020
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to know when HTTPmessage has finished

    Quote Originally Posted by ChrisW67 View Post
    Server and client are somewhat arbitrary. Perhaps I should word it this way, in the simple case the receiver knows the transmission is finished when the sender closes the socket (see Fortune Server Example). At its simplest HTTP operates that way. In practice though, network socket connections are kept open and the higher level protocol tracks the start and end of transactions.
    I do not know which "http server example" you are referring to. There isn't one here. Can you provide a link?
    Chris:

    The server sample is at https://github.com/qt-labs/qthttpserver.

    Since the app I am calling the clientdoes not seem to know when it has finished sending the file I cannot close from that end. I switched the server to use console mode and notices that QTcpSocket does not have a finished slot so that explains that end. the Server only gets the finished notification when the server sends back a status message.

    Bruce

  6. #6
    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: How to know when HTTPmessage has finished

    QTcpSocket has a closed() signal, which the server can use to detected the other end closing the connection.

    I assume the client and its behaviour is under your control. If you are not getting a finished() then there could be something wrong with the PUT or POST transaction and its payload. Are you getting an error signal?
    What is going in mPostMsgData and how is it constructed?

    Can you post a small, self-contained example that fails?

  7. #7
    Join Date
    May 2020
    Posts
    9
    Qt products
    Qt5
    Platforms
    Windows Android

    Default Re: How to know when HTTPmessage has finished

    Chris:
    I pushed a small test client up to https://gitlab.com/bclay/http-test-client. I left code segments in that should support https that relate to a previous problem I reported but that code is commented out. Once I see what is wrong here I would like to get back to that. It also is using the same qt lab httpserver

    Bruce

Similar Threads

  1. the program has unexpectedly finished
    By narlapavan in forum Qt Programming
    Replies: 9
    Last Post: 9th July 2012, 10:04
  2. How to create finished executable?
    By Pyrrha in forum Newbie
    Replies: 7
    Last Post: 19th August 2011, 01:23
  3. application finished, now what?
    By jbca in forum Newbie
    Replies: 2
    Last Post: 11th August 2010, 07:09
  4. which one has finished with QFutrueWatcher
    By wookoon in forum Qt Programming
    Replies: 2
    Last Post: 27th July 2010, 13:41
  5. QProcess::finished()
    By T1c4L in forum Qt Programming
    Replies: 11
    Last Post: 9th July 2008, 21:06

Tags for this Thread

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.