HTTP Stay-Alive和Websockets之间的行为区别是什么? [英] What's the behavioral difference between HTTP Stay-Alive and Websockets?

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

问题描述

我最近一直在使用websockets。创建了我自己的服务器,并有一个公开演示。我没有这样详细的经验或知识re:http。 (虽然因为websocket请求是升级的http请求,我有一些。)

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.)

在我的结尾,服务器报告每次命中的详细信息。其中有一堆http keep-alive请求。我的服务器不处理它们,因为它们不是websocket请求。但它让我好奇心。

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

关于websockets的重要一点是连接保持活跃。然后你可以在两个方向传递信息(甚至同时)。我已经读过,Stay-Alive HTTP连接是一个相对较新的开发(我不知道人们有多少年的时间,只是它只包含在最新的标准中 - 1.1 - 现在真的老了吗?)

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 Stay-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?)

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

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?

推荐答案

自HTTP 1.0起保持活动HTTP标头,用于表示HTTP客户端要维护与HTTP服务器的持久连接。主要目的是消除为每个HTTP请求打开TCP连接的需要。但是,虽然打开了持久连接,但客户端和服务器之间的通信协议仍然遵循基本的HTTP请求/响应模式。换句话说,服务器端无法将数据推送到客户端。

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是完全不同的机制,用于建立持久的全双工连接。通过这种全双工连接,服务器端可以将数据推送到客户端,客户端应该随时处理来自服务器端的数据。

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.

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

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

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

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