Comet 现在是否已因服务器发送事件和 WebSocket 而过时? [英] Is Comet obsolete now with Server-Sent Events and WebSocket?

查看:25
本文介绍了Comet 现在是否已因服务器发送事件和 WebSocket 而过时?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

还是服务器发送事件和 WebSocket 会取代 Comet 技术?

or do Server-Sent Events and WebSocket replace Comet techniques?

推荐答案

Comet 是一组通常使用 HTTP 长轮询实现的技术原理/通信模式.它使服务器能够按需向浏览器发送数据(即服务器推送).当前的 Comet 实现需要客户端一些复杂的 Javascript 和服务器端的支持(对于长期持有的请求).

Comet is a set of technology principles/communication patterns that are typically implemented using HTTP long-poll. It enables a server to send data to the browser on demand (i.e. server push). Current comet implementations require some complex Javascript on the client side and support from the server-side (for long-held requests).

Server-Sent Events 是一种标准 (HTML5) 浏览器 API,用于启用此类按需服务器推送.您可以将 Server-Sent Events 视为使用复杂的 Javascript 完成的操作并将其下推到浏览器本身中.

Server-Sent Events is a standard (HTML5) browser API for enabling this sort of on demand server push. You can think of Server-Sent Events as taking what has been done with complex Javascript and pushing it down into the browser itself.

WebSockets 允许浏览器与支持 WebSocket 的服务器建立持久的全双工/双向连接.它不需要客户端像 AJAX/long-poll 一样保持定期向服务器发出 HTTP 请求以保持连接.一旦建立连接,与正常 HTTP/HTTP 长轮询的开销相比,每条消息的开销非常低(几个字节).您可以使用 WebSockets 进行高效的服务器推送,但这只是一个应用程序.

WebSockets allows a browser to establish a persistent full-duplex/bi-directional connection to a server with WebSocket support. It does not require the client to keep making periodic HTTP requests to the server in order to maintain the connection as with AJAX/long-poll. Once the connection is established the overhead per message is very low (a few bytes) compared to the overhead with normal HTTP/HTTP long-poll. You can use WebSockets for efficient server push, but this is just one application.

还有建立在 AJAX/comet/WebSockets 传输层上的库,以提供诸如会话管理、频道、广播、发布订阅等内容.CometD 就是一个例子.另一个流行的例子是 Socket.IO.如果 WebSockets 可用于底层传输,则两者都支持 WebSockets,如果 WebSockets 不可用,则它们也支持标准 AJAX/长轮询.

There are also libraries that build on the AJAX/comet/WebSockets transport layer to provide things like session management, channels, broadcast, pubsub, etc. CometD is an example of this. Another popular example is Socket.IO. Both support WebSockets if it is available for the underlying transport but also support standard AJAX/long-poll if WebSockets is not available.

这篇关于Comet 现在是否已因服务器发送事件和 WebSocket 而过时?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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