HTTP 保持连接和 TCP 保持连接 [英] HTTP Keep Alive and TCP keep alive

查看:46
本文介绍了HTTP 保持连接和 TCP 保持连接的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

HTTP Keep Alive 是如何实现的?它内部是否使用 TCP Keep Alive?如果没有,服务器如何检测客户端是死是活?

How is HTTP Keep Alive implemented? Does it internally use TCP Keep Alive? If not, how does the server detect if the client is dead or alive?

推荐答案

HTTP Keep-Alive 是 HTTP 协议的一个特性.实现了 Keep-Alive 功能的 Web 服务器必须定期检查连接/套接字(对于传入的 HTTP 请求)自它发送最后一个 HTTP 响应以来的时间跨度(以防有相应的 HTTP 请求).如果在配置的保持活动时间(秒)之前没有收到 HTTP 请求,Web 服务器将关闭连接.在 Web 服务器完成关闭"后,将无法再发出 HTTP 请求.另一方面,TCP Keep-Alive 由 TCP 层的 OS 管理.HTTP Keep-Alive 和 TCP Keep-Alive 完全无关.

HTTP Keep-Alive is a feature of HTTP protocol. The web-server, implementing Keep-Alive Feature, has to check the connection/socket periodically (for incoming HTTP request) for the time span since it sent the last HTTP response (in case there was corresponding HTTP Request). If no HTTP request is received by the time of the configured keep-alive time (seconds) the web server closes the connection. No further HTTP request will be possible after the 'close' done by Web Server. On the other hand, TCP Keep-Alive is managed by OS in the TCP layer. HTTP Keep-Alive and TCP Keep-Alive is totally unrelated things.

这篇关于HTTP 保持连接和 TCP 保持连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆