HTTP Keep-Alive 和 Websockets 之间的行为差​​异是什么? [英] What's the behavioral difference between HTTP Keep-Alive and Websockets?

查看:19
本文介绍了HTTP Keep-Alive 和 Websockets 之间的行为差​​异是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我最近一直在详细研究 websockets.创建了我自己的服务器,并且有一个 公共演示.我没有如此详细的经验或知识:http.(虽然因为 websocket 请求升级为 http 请求,所以我有一些.)

在我这边,服务器会报告每次命中的详细信息.其中有一堆http keep-alive请求.我的服务器不处理它们,因为它们不是 websocket 请求.但它激起了我的好奇心.

关于 websockets 的全部重要事情是连接保持活跃.然后你可以双向传递消息(甚至同时).我读过 Keep-Alive HTTP 连接是一个相对较新的发展(我不知道人们的时间有多少年,只是它只包含在最新的标准 - 1.1 - 现在真的旧了吗?)

我想我可以假设两者之间存在行为差异,或者没有理由采用 websocket 标准?有什么区别?

解决方案

自 HTTP 1.0 以来的 Keep Alive HTTP 标头,用于指示 HTTP 客户端希望与 HTTP 服务器保持持久连接.主要目的是消除为每个 HTTP 请求打开 TCP 连接的需要.然而,当持久连接打开时,客户端和服务器之间的通信协议仍然遵循基本的 HTTP 请求/响应模式.换句话说,服务器端无法将数据推送到客户端.

WebSocket 是完全不同的机制,用于建立持久的全双工连接.通过这种全双工连接,服务器端可以将数据推送给客户端,客户端应该可以随时处理来自服务器端的数据.

引用维基百科上的相应条目以供参考:1) http://en.wikipedia.org/wiki/HTTP_persistent_connection2) http://en.wikipedia.org/wiki/WebSocket

I've been working with websockets lately in detail. Created my own server and there's a public demo. I don't have such detailed experience or knowledge re: http. (Although since websocket requests are upgraded http requests, I have some.)

On my end, the server reports details of each hit. Among them are a bunch of http keep-alive requests. My server doesn't handle them because they're not websocket requests. But it got my curiosity up.

The whole big thing about websockets is that the connection stays alive. Then you can pass messages in both directions (simultaneously even). I've read that the Keep-Alive HTTP connection is a relatively new development (I don't know how many years in people time, just that it's only included in the latest standard - 1.1 - is that actually old now?)

I guess I can assume that there's a behavioral difference between the two or there would have been no reason for a websocket standard? What's the difference?

解决方案

A Keep Alive HTTP header since HTTP 1.0, which is used to indicate a HTTP client would like to maintain a persistent connection with HTTP server. The main objects is to eliminate the needs for opening TCP connection for each HTTP request. However, while there is a persistent connection open, the protocol for communication between client and server is still following the basic HTTP request/response pattern. In other word, server side can't push data to client.

WebSocket is completely different mechanism, which is used to setup a persistent, full-duplex connection. With this full-duplex connection, server side can push data to client and client should be expected to process data from server side at any time.

Quoting corresponding entries on Wikipedia for reference: 1) http://en.wikipedia.org/wiki/HTTP_persistent_connection 2) http://en.wikipedia.org/wiki/WebSocket

这篇关于HTTP Keep-Alive 和 Websockets 之间的行为差​​异是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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