On 2016-05-16, Steven D'Aprano <st...@pearwood.info> wrote: > On Tue, 17 May 2016 02:06 am, Grant Edwards wrote: > >> This is not Python specific, though I'm turning to Python to do some >> experimentation and to try to prototype a solution. >> >> Is there any way to limit the number of connections a browser uses to >> download a web page? > > Well, you control the server. It's your own server, right? Can you not tell > the server to limit how many connections it accepts from any one client?
I tried two approaches on Linux using a Python server prototype that has some code I wrote that accepts connections and then calls SimpleHTTPRequestHandler. For starters I'm sticking with HTTP (no SSL) and just stuck a 2-second (delay to simulate SSL startup time) between the accept() returning and the call to the request handler . 1) Refuse to accept more than one connection at a time by closing the listening socket while there is an active connection. On both Firefox and Chrome, this gets you the initial HTML page and perhaps one addition file (css, js, png, whatever). The files that the browser normally requests using the addition 4-5 requests simply fail (broken img, missing css and js files). The Chrome network monitor thingy shows those as "failed". In my test case, only allowing a single connection resulted in 7 failed files out of the 9 which are loaded for the page. 2) Limit the listen() backlog to 0. On Linux, a 0 backlog doesn't prevent the stack from sending back a SYN/ACK in response to a SYN. It just prevents the connection from ACKing anything else that's sent by the client. This makes the client think the connection is open. In my tests, the browser then sits there waiting for a response on what it _thinks_ is an open TCP connection. It eventually times out and fails. It looks to me like the browsers decide how many connections to use (in my test case it's usually around 5), assigns individual files to each connection, and then presses "go". If any connection fails, stalls, or falls over, the files assigned to that connection are failed rather than fetched from an extant working connection. Next I'll try adding the SSL layer -- perhaps stalling the connection after the accept() and before the SSL handshake will have a different affect on the browser that stalling a plaintext TCP connection before responding to the request. -- Grant Edwards grant.b.edwards Yow! PARDON me, am I at speaking ENGLISH? gmail.com -- https://mail.python.org/mailman/listinfo/python-list