HTML5服务器端事件:EventSource与包装的WebSocket [英] HTML5 Server-Side Event: EventSource vs. wrapped WebSocket
问题描述
HTML5服务器发送事件(SSE)API是否仅仅是基于事件的受限制的API,位于HTML5 WebSockets之上?
在我看来, EventSource
只是一个 WebSocket
:
- 不能
.send()
数据 - 使用
text / event-stream
format - 触发动态命名(服务器定义)事件而不是
onmessage
Web服务器将事件推送到客户端设备的想法非常有趣。这个API是否具有任何牵引力?
我认为异步事件模型在与Node结合时会很漂亮,但在我的ASP中没有看到很多用例。 NET世界。
服务器发送事件在Web套接字只需要服务器推送的应用程序中非常有用适用于需要双向快速通信的应用程序。
服务器发送事件是一个很好的解决方案的例子是:
- 股票价值变动
- 新闻提要
服务器已发送事件会执行一些内置于Web套接字中的内容,例如自动重新连接和 eventIDs 。
<截至今天,Server Sent事件还支持更广泛的Web浏览器,支持Safari(仅支持Web套接字的旧草稿)和Opera(默认情况下禁用Web套接字,并使用较旧的草稿)。
了解更多信息使用服务器发送的事件进行流更新的服务器已发送事件。
Is the HTML5 Server-Sent Events (SSE) API just a restricted, event-based API on top of HTML5 WebSockets?
It seems to me that an EventSource
is just a WebSocket
that:
- Cannot
.send()
data - Uses the
text/event-stream
format - Fires dynamically-named (server-defined) events instead of
onmessage
The idea of the web server pushing events down to client devices is quite intriguing. Does this API have any traction?
I imagine the async event model would work beautiful when couple with Node, but not seeing a lot of use cases for this in my ASP.NET world.
Server Sent Events is useful in applications that only needs server push while Web Sockets are good for applications that needs fast communications in both directions.
Examples where Server Sent Events are a good solution are:
- Stock Value changes
- News feeds
Server Sent Events do some more things that is not built-in in Web Sockets, such as automatic reconnection and eventIDs.
Server Sent events also has broader web browser support as of today, with support in Safari (only support older drafts of Web Sockets) and Opera (has Web Sockets disabled by default, and uses an older draft).
Read more about Server Sent Events on Stream Updates with Server-Sent Events.
这篇关于HTML5服务器端事件:EventSource与包装的WebSocket的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!