简体   繁体   English

Websocket,Server Sent Events(SSE)和HTTP2的Server Pushing之间有什么区别?

[英]What is the difference between Websocket,Server Sent Events (SSE) and HTTP2's Server Pushing?

Can someone brief about the difference between these looking-similar techniques? 有人可以简要介绍这些看似相似的技术之间的区别吗?

  • Websocket 的WebSocket
  • Server sent events (SSE) 服务器发送事件(SSE)
  • HTTP2's Server Pushing HTTP2的服务器推送

I knew all these 3 are " pushing " response from server instead of requesting by the client. 我知道所有这3个都是“ 推动 ”来自服务器的响应, 而不是客户端的请求。

At the first look , it seems all are same .I need to get more clarity about the differences. 初看起来 ,似乎都是一样的 。我需要更清楚地了解差异。

Websockets: asynchronous communication in both directions. Websockets:双向异步通信。 So far doesn't work well with HTTP/2, but efforts are ongoing to make it so. 到目前为止,HTTP / 2并不能很好地运行,但正在努力实现这一目标。 (For example WISH and websockets2-over-http2 .) (例如WISHwebsockets2-over-http2 。)

SSE: server can notify the browser of events. SSE:服务器可以通知浏览器事件。 Uses normal HTTP and works well even with HTTP/2. 使用普通的HTTP,即使使用HTTP / 2也能正常工作。 It's possible to emulate asynchronous communication in both directions with SSE by issuing notifications from client to server via regular POST requests, in HTTP/2 these requests go in the same socket with everything else for the same origin and therefore the cost of establishing a new connection can be avoided. 通过常规POST请求从客户端向服务器发出通知,可以通过SSE模拟双向异步通信,在HTTP / 2中,这些请求与同一来源的所有其他请求在同一个套接字中,因此建立新连接的成本可以避免。 However, there may be processing costs on the server side for processing a POST request which are greater than using native websockets. 但是,服务器端处理POST请求的处理成本可能高于使用本机websockets。

HTTP/2 Push: absolutely unrelated to the two above, it is a mechanism for a server to push assets to the browser in advance. HTTP / 2推送:与上面两者完全无关,它是服务器提前将资源推送到浏览器的机制。 Possible application: sending CSSs and Javascripts while the PHP engine is creating the HTML . 可能的应用: 在PHP引擎创建HTML时发送CSS和Javascripts In theory, HTTP/2 Push and SSE can be combined to make events available to the browser without the initial round-trip delay. 理论上,HTTP / 2 Push和SSE可以组合在一起,使浏览器无需初始往返延迟即可使用事件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM