http2 TCP连接何时关闭?

编程入门 行业动态 更新时间:2024-10-23 01:49:32
本文介绍了http2 TCP连接何时关闭?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我了解到http2使用一个tcp连接来服务多个请求,例如,如果我请求包含a.css和a.js的index.html,则这三个请求将在一个tcp连接中完成.

I understand that http2 uses one tcp connection to serve multiple requests, for example, if I request index.html which contains a.css and a.js, these three requests will be done in one tcp connection.

如果用户单击index2.html会发生什么?此请求是否仍使用相同的以前的tcp连接?如果是这样,浏览器是否会保持连接打开状态,直到用户关闭浏览器?在服务器端,服务器是否始终保持许多连接打开?

What happens if user clicks index2.html? does this request still use the same previous tcp connection? If so, will the browser keep the connection open until user closes the browser? And on the server side, does the server keep many connections open all the time?

推荐答案

使用HTTP/2时,浏览器通常每个域仅打开一个连接.

When using HTTP/2, browsers typically open only one connection per domain.

在您的示例中,index2.html将通过与index.html,a.css和a.js相同的TCP连接发送.

In your example, index2.html will be sent on the same TCP connection that was used for index.html, a.css and a.js.

在HTTP/2中,请求是在同一TCP连接上多路复用的,因此浏览器可以并发发送它们,而无需等待先前的请求得到响应.

In HTTP/2 requests are multiplexed on the same TCP connection, so that the browser can send them concurrently, without waiting for a previous request to be responded to.

浏览器和服务器均具有TCP连接的空闲超时. 如果连接空闲时间足够长,则任何一方都将关闭该连接-空闲超时较短的一方可以节省资源. 例如,您可以打开与wikipedia的连接,执行一些请求,然后离开该选项卡并进行其他操作. 一段时间(通常为30秒)后,浏览器将关闭与wikipedia的TCP连接.

Both browsers and servers have an idle timeout for TCP connections. If the connection is idle for long enough, it will be closed by either party - the one that has the shorter idle timeout, to save resources. For example, you may open a connection to a wikipedia, perform a few requests, and then leave that tab and work on something else. After a while (typically 30 seconds) the browser will close the TCP connection to wikipedia.

在服务器端,服务器将保持来自各个客户端的连接保持打开状态,直到它们被客户端关闭或直到服务器端空闲超时触发为止,这时由服务器启动了TCP的关闭连接.

On the server side, the server will keep the connections from various clients open, until they are either closed by the client or until the server-side idle timeout fires, at which point it's the server that initiated the close of the TCP connection.

使用HTTP/2,服务器必须维护的连接数大大少于使用HTTP/1.1的连接数. 使用HTTP/2,每个客户端服务器仅需维护1个TCP连接.使用HTTP/1.1,服务器必须每个客户端通常维护2-8个TCP连接.

With HTTP/2, the number of connections that a server has to maintain is vastly less than it was with HTTP/1.1. With HTTP/2, a server has to maintain just 1 TCP connection per client; with HTTP/1.1, the server had to maintain typically 2-8 TCP connections per client.

更多推荐

http2 TCP连接何时关闭?

本文发布于:2023-11-01 20:09:01,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1550288.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:TCP

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!