Why does chrome not establish the connection directly after the dns lookup?












0














I have the problem that Chrome is waiting for something after the DNS lookup before establishing the connection.
My problem -> (https://imgur.com/qA5ADOa)
On the picture you can see that after the dns lookup there is a big gap and the request took 313ms although all values together are maximum 16ms.
Apache on this picture -> (https://imgur.com/UI4ToDu).
What does apache do that problem does not occur? On this picture you can see very well that problem does not occur at apache.



I am writing a simple web server in C++ just for practice. I test the webserver with the Chrome Browser. The code is very simple and without errorhandling, here the part after the socket creation with hard coded response:



std::memset(&myAddr, 0, sizeof(myAddr));
myAddr.sin_family = AF_INET;
myAddr.sin_addr.s_addr = INADDR_ANY;
myAddr.sin_port = htons(80);

bind(acceptSock, (sockaddr *)&myAddr, sizeof(myAddr));

listen(acceptSock, 5);

clientSock = accept(acceptSock, (sockaddr *)&clientAddr, &clientAddrLen);

std::vector<char> recvbuf(BUFFER_LENTH);
recv(clientSock, &recvbuf[0], recvbuf.size(), 0);

std::ifstream file("index.html");
if (file.is_open()) {
std::string content;
std::string buf;
while (std::getline(file, buf)) {
content += buf;
buf.clear();
}

file.close();

size_t contentLength = content.size();

std::string sendbuf = "HTTP/1.1 200 OKrn";
sendbuf += "Content-Type: text/html; charset=UTF-8rn";
sendbuf += "Content-Length: " + std::to_string(contentLength) + "rn";
sendbuf += "Server: meinWebServerrn";
sendbuf += "rn";
sendbuf += content;

send(clientSock, sendbuf.c_str(), sendbuf.size(), 0);
}



  • What can I do to prevent this problem?

  • Why and what is Chrome waiting for after the lookup?










share|improve this question



























    0














    I have the problem that Chrome is waiting for something after the DNS lookup before establishing the connection.
    My problem -> (https://imgur.com/qA5ADOa)
    On the picture you can see that after the dns lookup there is a big gap and the request took 313ms although all values together are maximum 16ms.
    Apache on this picture -> (https://imgur.com/UI4ToDu).
    What does apache do that problem does not occur? On this picture you can see very well that problem does not occur at apache.



    I am writing a simple web server in C++ just for practice. I test the webserver with the Chrome Browser. The code is very simple and without errorhandling, here the part after the socket creation with hard coded response:



    std::memset(&myAddr, 0, sizeof(myAddr));
    myAddr.sin_family = AF_INET;
    myAddr.sin_addr.s_addr = INADDR_ANY;
    myAddr.sin_port = htons(80);

    bind(acceptSock, (sockaddr *)&myAddr, sizeof(myAddr));

    listen(acceptSock, 5);

    clientSock = accept(acceptSock, (sockaddr *)&clientAddr, &clientAddrLen);

    std::vector<char> recvbuf(BUFFER_LENTH);
    recv(clientSock, &recvbuf[0], recvbuf.size(), 0);

    std::ifstream file("index.html");
    if (file.is_open()) {
    std::string content;
    std::string buf;
    while (std::getline(file, buf)) {
    content += buf;
    buf.clear();
    }

    file.close();

    size_t contentLength = content.size();

    std::string sendbuf = "HTTP/1.1 200 OKrn";
    sendbuf += "Content-Type: text/html; charset=UTF-8rn";
    sendbuf += "Content-Length: " + std::to_string(contentLength) + "rn";
    sendbuf += "Server: meinWebServerrn";
    sendbuf += "rn";
    sendbuf += content;

    send(clientSock, sendbuf.c_str(), sendbuf.size(), 0);
    }



    • What can I do to prevent this problem?

    • Why and what is Chrome waiting for after the lookup?










    share|improve this question

























      0












      0








      0







      I have the problem that Chrome is waiting for something after the DNS lookup before establishing the connection.
      My problem -> (https://imgur.com/qA5ADOa)
      On the picture you can see that after the dns lookup there is a big gap and the request took 313ms although all values together are maximum 16ms.
      Apache on this picture -> (https://imgur.com/UI4ToDu).
      What does apache do that problem does not occur? On this picture you can see very well that problem does not occur at apache.



      I am writing a simple web server in C++ just for practice. I test the webserver with the Chrome Browser. The code is very simple and without errorhandling, here the part after the socket creation with hard coded response:



      std::memset(&myAddr, 0, sizeof(myAddr));
      myAddr.sin_family = AF_INET;
      myAddr.sin_addr.s_addr = INADDR_ANY;
      myAddr.sin_port = htons(80);

      bind(acceptSock, (sockaddr *)&myAddr, sizeof(myAddr));

      listen(acceptSock, 5);

      clientSock = accept(acceptSock, (sockaddr *)&clientAddr, &clientAddrLen);

      std::vector<char> recvbuf(BUFFER_LENTH);
      recv(clientSock, &recvbuf[0], recvbuf.size(), 0);

      std::ifstream file("index.html");
      if (file.is_open()) {
      std::string content;
      std::string buf;
      while (std::getline(file, buf)) {
      content += buf;
      buf.clear();
      }

      file.close();

      size_t contentLength = content.size();

      std::string sendbuf = "HTTP/1.1 200 OKrn";
      sendbuf += "Content-Type: text/html; charset=UTF-8rn";
      sendbuf += "Content-Length: " + std::to_string(contentLength) + "rn";
      sendbuf += "Server: meinWebServerrn";
      sendbuf += "rn";
      sendbuf += content;

      send(clientSock, sendbuf.c_str(), sendbuf.size(), 0);
      }



      • What can I do to prevent this problem?

      • Why and what is Chrome waiting for after the lookup?










      share|improve this question













      I have the problem that Chrome is waiting for something after the DNS lookup before establishing the connection.
      My problem -> (https://imgur.com/qA5ADOa)
      On the picture you can see that after the dns lookup there is a big gap and the request took 313ms although all values together are maximum 16ms.
      Apache on this picture -> (https://imgur.com/UI4ToDu).
      What does apache do that problem does not occur? On this picture you can see very well that problem does not occur at apache.



      I am writing a simple web server in C++ just for practice. I test the webserver with the Chrome Browser. The code is very simple and without errorhandling, here the part after the socket creation with hard coded response:



      std::memset(&myAddr, 0, sizeof(myAddr));
      myAddr.sin_family = AF_INET;
      myAddr.sin_addr.s_addr = INADDR_ANY;
      myAddr.sin_port = htons(80);

      bind(acceptSock, (sockaddr *)&myAddr, sizeof(myAddr));

      listen(acceptSock, 5);

      clientSock = accept(acceptSock, (sockaddr *)&clientAddr, &clientAddrLen);

      std::vector<char> recvbuf(BUFFER_LENTH);
      recv(clientSock, &recvbuf[0], recvbuf.size(), 0);

      std::ifstream file("index.html");
      if (file.is_open()) {
      std::string content;
      std::string buf;
      while (std::getline(file, buf)) {
      content += buf;
      buf.clear();
      }

      file.close();

      size_t contentLength = content.size();

      std::string sendbuf = "HTTP/1.1 200 OKrn";
      sendbuf += "Content-Type: text/html; charset=UTF-8rn";
      sendbuf += "Content-Length: " + std::to_string(contentLength) + "rn";
      sendbuf += "Server: meinWebServerrn";
      sendbuf += "rn";
      sendbuf += content;

      send(clientSock, sendbuf.c_str(), sendbuf.size(), 0);
      }



      • What can I do to prevent this problem?

      • Why and what is Chrome waiting for after the lookup?







      c++ google-chrome






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Dec 28 '18 at 0:17









      Rondis

      12




      12
























          0






          active

          oldest

          votes











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          autoActivateHeartbeat: false,
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952296%2fwhy-does-chrome-not-establish-the-connection-directly-after-the-dns-lookup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          0






          active

          oldest

          votes








          0






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes
















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53952296%2fwhy-does-chrome-not-establish-the-connection-directly-after-the-dns-lookup%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Monofisismo

          Angular Downloading a file using contenturl with Basic Authentication

          Olmecas