现在,Comet是否已被服务器发送的事件和WebSocket淘汰了? [英] Is Comet obsolete now with Server-Sent Events and WebSocket?

查看:168
本文介绍了现在,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).

服务器发送的事件是用于启用这种按需服务器推送的标准(HTML5)浏览器API。您可以将服务器发送的事件视为使用复杂的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支持的服务器的持久性全双工/双向连接。它不需要客户端定期向服务器发出HTTP请求以维持与AJAX /长轮询一样的连接。建立连接后,与普通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 / long-poll。

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天全站免登陆