Client/browser sends multiple http-requests to server

I have written a few simple lines to find out what the browser is sending to the server when requesting a new page. This is from the server (there is no error checking, this is for testing purposes only) .

connections[i] = accept (server_socket, null, null);
cout << recv (connections[i], buffer, 600, 0) << "\n\n";
cout << buffer << "\n\n";

i++;

Then I copy this entire code and repeat it 5 times. Now that I have this ready, I start the server and open up my browser (Chrome). In the adressfield am writing localhost:27015, then I press enter. So now lets see what’s happening in the server console …

First, it prints out the number of bytes received (that’s what recv() returns if no errors have occurred). And after that, the entire http request will be printed out. So this is for the first socket. But then it prints zero(0) for the next socket, no message received. And another zero for a third socket, without any message received here either (zero means that the client has closed the socket).

After that, the program is blocked. So apparently Chrome created 3 connections when I wrote localhost:27015 in the browser. The first comes with a full message / http request, but what’s the purpose of the other 2? They both return zero(0). Why do they create 2 additional connections that they then close immediately? (Or have them been paused maybe?)

I also do not think it’s favicon that causes this. Because I get a separate request for favicon, as soon as I respond to the first http request. Note that this happens only with Chrome. IE only creates one connection initially.


Neo

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.