哪些具体用例需要通过 WebSockets 和长轮询使用 BOSH?
BOSH 是...
一种传输协议,通过有效地使用多个同步 HTTP 请求/响应对来模拟两个实体(例如客户端和服务器)之间的长期双向 TCP 连接的语义,而无需使用频繁的轮询或分块回应。
这听起来像 WebSockets 和 HTTP 长轮询,只不过它使用两个打开的 HTTP 连接而不是一个不扩展 HTTP 协议。
这两种协议之间有什么区别,什么用例更喜欢 WebSocket 而不是 BOSH?
BOSH is...
a transport protocol that emulates the semantics of a long-lived, bidirectional TCP connection between two entities (such as a client and a server) by efficiently using multiple synchronous HTTP request/response pairs without requiring the use of frequent polling or chunked responses.
This sounds like WebSockets and HTTP long-polling except that it uses two open HTTP connections instead of one and doesn't extend the HTTP protocol.
What are the differences between the two protocols, and what use case would prefer WebSockets over BOSH?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
首先让我谈谈 WebSockets 准备情况:
Hixie-76 协议在 Chrome、Safari 和 iOS(iPhone 和 iPad)中默认提供并启用。 Hixie-76 协议也已发布,但在 Firefox 4 和 Opera 11 中默认处于禁用状态。 socket-js 项目是一个 Flash shim/polyfill,它为任何带有 Flash 的浏览器添加了 WebSocket (Hixie-76) 支持。
换句话说,WebSockets 几乎适用于所有浏览器。
Opera 和 Mozilla 选择默认禁用该协议的原因是理论上的担忧,即可能存在一些损坏的 HTTP 代理/中介,可能会使用该协议的 Hixie 版本进行攻击/中毒。同样的担忧也适用于 Flash,但 Mozilla 和 Opera 认为对其发布的代码负有更高的责任。该协议的 HyBi 版本(该协议已移至 IETF HyBi 工作组)解决了安全问题。
Mozilla、Opera、Google 和 Microsoft 都在致力于 HyBi 协议实现(尽管 Microsoft 正在将其协议维护为 暂时单独下载)。 HyBi 有一个 web-socket-js 分支 -07 支持。
更新:截至 2013 年 2 月,最新的 HyBi/IETF RFC 6455规范受 Chrome 14、Firefox 7、IE10、Opera 12.1、Safari 6.0 和 web-socket-js Flash shim/polyfill。在移动设备上,iOS 6.0、Opera Mobile 12.1、Chrome 14 for Android、Firefox 7 for Android 和 Blackberry 7 上的 Safari 支持 IETF6455。原始默认 Android 浏览器不支持任何 WebSocket。
WebSocket 服务器很容易实现。有许多独立和插件实现,其中大多数支持 Hixie-76 和 HyBi 协议版本:
BOSH 与 WebSockets:
消息。在 BOSH 中,每条消息都有 HTTP 请求和响应标头(每次往返很容易超过 180 个字节)。此外,每条消息都用 XML 封装(据说是可选的,但规范没有定义如何封装),并带有多个与会话相关的属性。
更新:
刚刚发现 Ian Fette 讨论 WebSocket 相对于类似于 BOSH 的 Channel API 的优势 (at 44:00)
First let me address WebSockets readiness:
WebSockets implementation of the Hixie-76 protocol are shipped and enabled by default in Chrome, Safari and iOS (iPhone and iPad). The Hixie-76 protocol is also shipped but disabled by default in Firefox 4 and Opera 11. The web-socket-js project is a Flash shim/polyfill that adds WebSocket (Hixie-76) support to any browser with Flash.
In other words, WebSockets is available for almost every browser in the wild.
The reason why Opera and Mozilla chose to disable the protocol by default is because of a theoretical concern that there might be some broken HTTP proxies/intermediaries that could be attacked/poisoned using the Hixie versions of the protocol. The same concern applies to Flash but Mozilla and Opera felt a higher duty of responsibility for code that they ship. The HyBi versions of the protocol (the protocol was moved to the IETF HyBi working group) address the security concern.
Mozilla, Opera, Google, and Microsoft are all working on HyBi protocol implementations (although Microsoft is maintaining theirs as a separate download for now). There is a branch of web-socket-js with HyBi-07 support.
Update: As of Feb, 2013, the latest HyBi/IETF RFC 6455 spec is supported by Chrome 14, Firefox 7, IE10, Opera 12.1, Safari 6.0 and by the web-socket-js Flash shim/polyfill. On mobile devices IETF6455 is supported by Safari on iOS 6.0, Opera Mobile 12.1, Chrome 14 for Android, Firefox 7 for Android, and Blackberry 7. The original default Android browser does not have any WebSocket support.
WebSocket servers are easy to implement. There are numerous standalone and plugin implementations most of which support both Hixie-76 and HyBi protocol versions:
BOSH vs WebSockets:
messages. In BOSH, every message has HTTP request and response headers (easily 180+ bytes for each round-trip). In addition, each message is wrapped in XML (supposedly optional but the spec doesn't define how) with several session related attributes.
Update:
Just found a video where Ian Fette discusses the advantages of WebSockets over the Channel API which is similar to BOSH (at 44:00)