0

TL;DR: client keeps making new connections from different ports even though I am only opening one tab on my client computer.

I wrote the following python multiple-client-proxy socket:

my_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
my_socket.bind((IP, PORT))
my_socket.listen(5)
print("-> Waiting for connections...")

while True:
    client_socket, address = my_socket.accept()
    t.start_new_thread(on_new_client, (client_socket, address))

using this "start_new_thread" method that I saw on some answer here. I was expecting the thread to start and then the program to go to the beginning of the loop and block until another client tries to connect (e.g. another computer or by opening another tab).

But to my surprise, I began to see different connections while using only my one testing client, loading the page only on one tab. They were from my same client but using different client ports.

According to the console, it actually immediately began with 2 connections:

-> Connected to ('10.100.102.10', 51883)
-> Connected to ('10.100.102.10', 51884)

and some more during the serving session:

-> First request is:
GET / HTTP/1.1
Host: bank.com
Connection: keep-alive
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Accept-Encoding: gzip, deflate
Accept-Language: he-IL,he;q=0.9,en-US;q=0.8,en;q=0.7


-> Connected to ('10.100.102.10', 51885)

^(notice this connection message at the end, even after I already got a GET request from one of the other connections)

It is also important to note that I have a message for closing a connection so I'm guessing the problem is not that the other connections closed.

Why does the client keep making new connections from different ports even though I am only opening one tab on my client computer?

rubberband
  • 25
  • 1
  • 5
  • When you one web page then it has to read may files - HTML, CSS, JavaScript, images, fonts. And browser may read 4 files (or maybe 8) at the same time from one server. And if page uses CDN for images/css/javascript then browser may read another 4 files at the same time. And if page use two servers CDN then it will read even more files at the same time. This way you can see web page faster. – furas Jan 09 '21 at 22:23
  • and before it will read page it has to first connect with DNS to conver address to IP - and it may need also few connections. But I don't know if it will connect directly or using proxy – furas Jan 09 '21 at 22:29

0 Answers0