有一篇很全面的文章, 其中讲到了websocket和http/2的对比(http/1 不支持‘服务器端事件SSE’) : https://blog.sessionstack.com/how-javascript-works-deep-dive-into-websockets-and-http-2-with-sse-how-to-pick-the-right-path-584e6b8e3bf7

websocket请求头很小, 数据帧(frame)控制也很简单, 所以低延时(low latency)
由于websocket是先由http连接后, 发送upgrade请求后“升级”上去的一个新连接, 所以在安全性, 负载均衡等方面, 不如http/https

优点

WebSockets will certainly survive the domination of HTTP/2 + SSE, mainly because it’s a technology already well adopted and, in very specific use cases, it has an advantage over HTTP/2 as it has been built for bidirectional capabilities with less overhead (e.g. headers).
Say you want to build a Massive Multiplayer Online Game that needs a huge amount of messages from both ends of the connection. In such a case, WebSockets will perform much, much better.
In general, use WebSockets whenever you need a truly low-latency, near realtime connection between the client and the server. Keep in mind that this might require rethinking how you build your server-side applications, as well as shifting the focus on technologies like event queues.

缺点

WebSockets can often be a source of pain when considering compatibility with existing web infrastructure as it upgrades an HTTP connection to a completely different protocol that has nothing to do with HTTP.
Scale and security: Web components (Firewalls, Intrusion Detection, Load Balancers) are built, maintained and configured with HTTP in mind, an environment that large/critical applications will prefer in terms of resiliency, security, and scalability.

相关文章:

  • 2021-05-30
  • 2019-10-28
  • 2022-02-19
  • 2021-06-23
  • 2022-01-19
  • 2022-12-23
  • 2022-03-05
  • 2022-12-23
猜你喜欢
  • 2020-03-24
  • 2021-12-20
  • 2023-03-29
  • 2021-11-23
  • 2021-11-07
  • 2022-01-14
  • 2021-05-21
相关资源
相似解决方案