Why are there multiple TCP connections to the server when I open one website page in my Chrome?

不羁岁月 提交于 2021-02-17 05:29:12

问题


The website is developed in SpringBoot and deployed in Linux server. When I open one website page in Chrome, and I open TCP Viewer, I see that there are multiple TCP connections from my computer to the server. They are using totally different ports.

And I check the network tab in Chrome DevTool, I see there is Keep-Alive in the requst header. I guess it is using Http 1.1 and long connections.

So this confused me. Since it is long connection, all the content should be through one TCP connection, why are there so many TCP connections?


回答1:


While HTTP/1.0 and HTTP/1.1 support persistent connections where multiple HTTP requests are handled within the same TCP connection, these requests are still handled on after each other within the same connection. If many resources are needed from a site this sequential loading using a single TCP connection would be too slow. Thus parallel loading using multiple TCP connection is done. Since most sites load many resources (main HTML, various CSS, JavaScript, images, fonts...) one sees multiple TCP connections used with most sites.

With HTTP/2 parallel loading within a single TCP connection is supported. In this case one will usually see only a single TCP connection to a site. Of course, if resources are loaded from multiple sites (i.e. ads, tracking ...) one will also see multiple TCP connections again - but only one per destination if HTTP/2 is used for the specific destination.



来源:https://stackoverflow.com/questions/52731867/why-are-there-multiple-tcp-connections-to-the-server-when-i-open-one-website-pag

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!