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. Prevent multiple TCP segments in post request
Qt 6.11 is out! See what's new in the release blog

Prevent multiple TCP segments in post request

Scheduled Pinned Locked Moved Unsolved General and Desktop
30 Posts 5 Posters 4.9k Views 2 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.
  • Christian EhrlicherC Offline
    Christian EhrlicherC Offline
    Christian Ehrlicher
    Lifetime Qt Champion
    wrote on last edited by
    #4

    As said - it depends on the OS or whatever how much tcp packets are sent for one request. It does not affect anything on the http protocol. The problem must be somewhere else.

    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
    Visit the Qt Academy at https://academy.qt.io/catalog

    1 Reply Last reply
    1
    • V Offline
      V Offline
      vicsoftware
      wrote on last edited by vicsoftware
      #5

      It is Ubuntu 18, Nvidia Jetson AGX, Arm64

      Requests executes on same system, why curl and chrome sends single valid post request, but QT sends splitted segments and 2 requests?

      Christian EhrlicherC 1 Reply Last reply
      0
      • V vicsoftware

        It is Ubuntu 18, Nvidia Jetson AGX, Arm64

        Requests executes on same system, why curl and chrome sends single valid post request, but QT sends splitted segments and 2 requests?

        Christian EhrlicherC Offline
        Christian EhrlicherC Offline
        Christian Ehrlicher
        Lifetime Qt Champion
        wrote on last edited by
        #6

        @vicsoftware said in Prevent multiple TCP segments in post request:

        but QT sends splitted segments and 2 requests?

        It does not send two requests. It sends one request with two tcp packets. Maybe it's how write() is called on the socket or the moon phase or whatever.

        Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
        Visit the Qt Academy at https://academy.qt.io/catalog

        V 1 Reply Last reply
        0
        • Christian EhrlicherC Christian Ehrlicher

          @vicsoftware said in Prevent multiple TCP segments in post request:

          but QT sends splitted segments and 2 requests?

          It does not send two requests. It sends one request with two tcp packets. Maybe it's how write() is called on the socket or the moon phase or whatever.

          V Offline
          V Offline
          vicsoftware
          wrote on last edited by vicsoftware
          #7

          @Christian-Ehrlicher No. QT sends 2 request until "closed connection" error and every request has 2 TCP segments.
          Curl and chrome sends single request with 1 tcp segment.

          Here is 2 first QT request, third is chrome request forth is curl.
          Screenshot from 2021-10-12 14-05-50.png

          As we see length is 64 bytes for QT, and 185 for chrome and 222 for curl.

          But QT post has more headers and it shoud be longer bytes. It shows 64 bytes but:

          Screenshot from 2021-10-12 14-13-28.png

          Really tcp has 235 bytes.

          1 Reply Last reply
          0
          • Christian EhrlicherC Offline
            Christian EhrlicherC Offline
            Christian Ehrlicher
            Lifetime Qt Champion
            wrote on last edited by
            #8

            No. QT sends 2 request

            This is a new information.

            Qt only send two requests when you programmed it to do so.

            Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
            Visit the Qt Academy at https://academy.qt.io/catalog

            V 1 Reply Last reply
            0
            • Christian EhrlicherC Christian Ehrlicher

              No. QT sends 2 request

              This is a new information.

              Qt only send two requests when you programmed it to do so.

              V Offline
              V Offline
              vicsoftware
              wrote on last edited by vicsoftware
              #9

              @Christian-Ehrlicher No. I execute only single post from code. QT trying send second post before closing connection. It's look like.

              If it is only attempts to connect so it is not a problem.
              Problem with bad post from QT so server does not understand request.

              1 Reply Last reply
              0
              • Christian EhrlicherC Offline
                Christian EhrlicherC Offline
                Christian Ehrlicher
                Lifetime Qt Champion
                wrote on last edited by
                #10

                @vicsoftware said in Prevent multiple TCP segments in post request:

                QT trying send second post before closing connection. It's look like.

                It does not send a http request a second time when you don't ask for it.

                Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                Visit the Qt Academy at https://academy.qt.io/catalog

                V 1 Reply Last reply
                0
                • Christian EhrlicherC Christian Ehrlicher

                  @vicsoftware said in Prevent multiple TCP segments in post request:

                  QT trying send second post before closing connection. It's look like.

                  It does not send a http request a second time when you don't ask for it.

                  V Offline
                  V Offline
                  vicsoftware
                  wrote on last edited by vicsoftware
                  #11

                  @Christian-Ehrlicher Sorry but no. It is definitely QT behavior to resend request. I think. I am doing only one call:

                  const auto reply{ m_networkMan->post( request, data.toUtf8() ) };
                  

                  It is pushButton handler and it has single debug std::cout message only before connection error emitted.

                  QT GET request works and sends only one time.

                  1 Reply Last reply
                  0
                  • Christian EhrlicherC Offline
                    Christian EhrlicherC Offline
                    Christian Ehrlicher
                    Lifetime Qt Champion
                    wrote on last edited by
                    #12

                    Then please provide a minimal, reproducible example for us. I don't see why a http request should be sent twice when the other side does not request it.

                    Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                    Visit the Qt Academy at https://academy.qt.io/catalog

                    V 1 Reply Last reply
                    1
                    • Christian EhrlicherC Christian Ehrlicher

                      Then please provide a minimal, reproducible example for us. I don't see why a http request should be sent twice when the other side does not request it.

                      V Offline
                      V Offline
                      vicsoftware
                      wrote on last edited by vicsoftware
                      #13

                      @Christian-Ehrlicher If server powered off then after longer time i got Request error: "Host unreachable" and there is no requests at all in wireshark.

                      1 Reply Last reply
                      0
                      • V Offline
                        V Offline
                        vicsoftware
                        wrote on last edited by
                        #14

                        Why QT makes 2 tcp segments but other methods has 1 tcp segment. Someone can explain QT post behavior?

                        Christian EhrlicherC 1 Reply Last reply
                        0
                        • V vicsoftware

                          Why QT makes 2 tcp segments but other methods has 1 tcp segment. Someone can explain QT post behavior?

                          Christian EhrlicherC Offline
                          Christian EhrlicherC Offline
                          Christian Ehrlicher
                          Lifetime Qt Champion
                          wrote on last edited by
                          #15

                          @vicsoftware said in Prevent multiple TCP segments in post request:

                          Why QT makes 2 tcp segments but other methods has 1 tcp segment. Someone can explain QT post behavior?

                          Again: this has not much to do with Qt but with the underlying os. Maybe Qt writes the packet in two parts to the OS and curl only one. But this is completely irrelevant.

                          Qt Online Installer direct download: https://download.qt.io/official_releases/online_installers/
                          Visit the Qt Academy at https://academy.qt.io/catalog

                          V 1 Reply Last reply
                          0
                          • Christian EhrlicherC Christian Ehrlicher

                            @vicsoftware said in Prevent multiple TCP segments in post request:

                            Why QT makes 2 tcp segments but other methods has 1 tcp segment. Someone can explain QT post behavior?

                            Again: this has not much to do with Qt but with the underlying os. Maybe Qt writes the packet in two parts to the OS and curl only one. But this is completely irrelevant.

                            V Offline
                            V Offline
                            vicsoftware
                            wrote on last edited by
                            #16

                            @Christian-Ehrlicher And chrome extension only one. And python sends normal request. But QT does not. And sends it twice. And packet length wrong. Why?

                            1 Reply Last reply
                            0
                            • V Offline
                              V Offline
                              vicsoftware
                              wrote on last edited by vicsoftware
                              #17

                              Have tried online post service, and same QT code sends only single post request with 2 tcp segments.

                              Screenshot from 2021-10-12 15-28-31.png

                              1 Reply Last reply
                              0
                              • V Offline
                                V Offline
                                vicsoftware
                                wrote on last edited by vicsoftware
                                #18
                                This post is deleted!
                                1 Reply Last reply
                                0
                                • V Offline
                                  V Offline
                                  vicsoftware
                                  wrote on last edited by
                                  #19

                                  Simple curl code works:

                                  const std::string url{ "http://" + m_addr + "/od/2400/01" };
                                          CURL *curl;
                                          CURLcode res;
                                  
                                          curl_global_init(CURL_GLOBAL_ALL);
                                  
                                          curl = curl_easy_init();
                                          if(curl) {
                                              curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
                                              curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "\"00000001\"");
                                  
                                              res = curl_easy_perform(curl);
                                              if(res != CURLE_OK)
                                                  fprintf(stderr, "curl_easy_perform() failed: %s\n",
                                                          curl_easy_strerror(res));
                                  
                                              curl_easy_cleanup(curl);
                                          }
                                          curl_global_cleanup();
                                  

                                  QNetworkManager post failed.

                                  J.HilkJ JonBJ 2 Replies Last reply
                                  0
                                  • V vicsoftware

                                    Simple curl code works:

                                    const std::string url{ "http://" + m_addr + "/od/2400/01" };
                                            CURL *curl;
                                            CURLcode res;
                                    
                                            curl_global_init(CURL_GLOBAL_ALL);
                                    
                                            curl = curl_easy_init();
                                            if(curl) {
                                                curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
                                                curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "\"00000001\"");
                                    
                                                res = curl_easy_perform(curl);
                                                if(res != CURLE_OK)
                                                    fprintf(stderr, "curl_easy_perform() failed: %s\n",
                                                            curl_easy_strerror(res));
                                    
                                                curl_easy_cleanup(curl);
                                            }
                                            curl_global_cleanup();
                                    

                                    QNetworkManager post failed.

                                    J.HilkJ Offline
                                    J.HilkJ Offline
                                    J.Hilk
                                    Moderators
                                    wrote on last edited by
                                    #20

                                    @vicsoftware why do you post the code that "works" for you and not the one that doesn't!?!?!


                                    Be aware of the Qt Code of Conduct, when posting : https://forum.qt.io/topic/113070/qt-code-of-conduct


                                    Q: What's that?
                                    A: It's blue light.
                                    Q: What does it do?
                                    A: It turns blue.

                                    V 1 Reply Last reply
                                    1
                                    • V vicsoftware

                                      Simple curl code works:

                                      const std::string url{ "http://" + m_addr + "/od/2400/01" };
                                              CURL *curl;
                                              CURLcode res;
                                      
                                              curl_global_init(CURL_GLOBAL_ALL);
                                      
                                              curl = curl_easy_init();
                                              if(curl) {
                                                  curl_easy_setopt(curl, CURLOPT_URL, url.c_str() );
                                                  curl_easy_setopt(curl, CURLOPT_POSTFIELDS, "\"00000001\"");
                                      
                                                  res = curl_easy_perform(curl);
                                                  if(res != CURLE_OK)
                                                      fprintf(stderr, "curl_easy_perform() failed: %s\n",
                                                              curl_easy_strerror(res));
                                      
                                                  curl_easy_cleanup(curl);
                                              }
                                              curl_global_cleanup();
                                      

                                      QNetworkManager post failed.

                                      JonBJ Offline
                                      JonBJ Offline
                                      JonB
                                      wrote on last edited by JonB
                                      #21

                                      @vicsoftware
                                      Two comments:

                                      • As @Christian-Ehrlicher has said, you need to produce (minimal, test) Qt code, not curl code, if you want someone to look at it as a Qt issue.

                                      • You, and your program, are never supposed to care what is going on at the TCP packet level. Whether an application makes a request which gets passed as one TCP packet, or two, or other, should have no effect. We have all used TCP for years, with Qt or other toolkits, and never cared about this or noticed any behaviour such as you report with "errors" occurring. Again, for the record, it is basically down to the OS/TCP level how it chooses to packet-ise messages. Artefacts such as Nagle's algorithm will commonly affect the runtime packet behaviour.

                                      V 1 Reply Last reply
                                      0
                                      • J.HilkJ J.Hilk

                                        @vicsoftware why do you post the code that "works" for you and not the one that doesn't!?!?!

                                        V Offline
                                        V Offline
                                        vicsoftware
                                        wrote on last edited by vicsoftware
                                        #22

                                        @J-Hilk QT code posted above.

                                        1 Reply Last reply
                                        0
                                        • JonBJ JonB

                                          @vicsoftware
                                          Two comments:

                                          • As @Christian-Ehrlicher has said, you need to produce (minimal, test) Qt code, not curl code, if you want someone to look at it as a Qt issue.

                                          • You, and your program, are never supposed to care what is going on at the TCP packet level. Whether an application makes a request which gets passed as one TCP packet, or two, or other, should have no effect. We have all used TCP for years, with Qt or other toolkits, and never cared about this or noticed any behaviour such as you report with "errors" occurring. Again, for the record, it is basically down to the OS/TCP level how it chooses to packet-ise messages. Artefacts such as Nagle's algorithm will commonly affect the runtime packet behaviour.

                                          V Offline
                                          V Offline
                                          vicsoftware
                                          wrote on last edited by
                                          #23

                                          @JonB I have nanotec.com tcp controller C5-E-2-81. It has REST API to control driver. So i can only get/post. And i can't reproduce for you it. You do not have that controller.
                                          I tried online service and it works. But that service do not dispatch input data, it only receives post so it is not the same as controller.

                                          In this case, the question is why all other methods do but QT does not? It simple post but it does not work.

                                          1 Reply Last reply
                                          0

                                          • Login

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