为什么要使用 Socket.io? [英] Why should I use Socket.io?

查看:37
本文介绍了为什么要使用 Socket.io?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在学习 Node.js,目前正在学习 WebSockets.据我了解,Socket.io 旨在解决各种浏览器对 WebSockets 的不一致支持...如果您查看 caniuseWebSockets,看来 WebSockets 目前已经几乎完全支持.谁能解释为什么在这种情况下我应该使用 Socket.io 和 WebSockets?

I am learning Node.js and am currently studying WebSockets. As I understand it, Socket.io was intended to address inconsistent support that the various browsers had with WebSockets...If you check out caniuse WebSockets, it appears that WebSockets currently has practically full support. Can anyone explain why I should use Socket.io versus WebSockets in this case?

推荐答案

  1. 它可以让您优雅地降级为多种技术替代方案,以获得双向近时通信流(网络套接字、ajax 长轮询、闪存等)
  2. 截至 2013 年 3 月,该网站列出了 61% 支持的网络套接字.这不是实际上已满".
  3. 截至 2021 年 9 月,该网站列出了 98% 支持的网络套接字.所有现代浏览器都支持 Websocket.
  4. 它可以为您处理浏览器不一致和不同的支持级别
  5. (从正确的角度来看,前两件事基本上与 jQuery 创建的值相同)
  6. 除了基本的网络套接字之外,它还包括其他功能,例如对基本发布/订阅基础架构的房间支持以及自动重新连接等功能
  7. AFAIK 至少在目前,它比普通网络套接字更受欢迎,也更容易获得帮助.
  1. It handles graceful degradation for you to numerous technical alternatives to get bi-directional near-time communication flowing (web sockets, ajax long polling, flash, etc)
  2. As of March 2013 that site lists web sockets at 61% support. This is not "practically full".
  3. As of September 2021 that site lists web sockets at 98% support. All modern browser's support Websockets.
  4. It handles browser inconsistencies and varying support levels for you
  5. (these first 2 things are basically the same value created by jQuery, to put it in perspective)
  6. It includes additional features beyond bare bones web sockets such as room support for basic publish/subscribe infrastructure and things like automatic reconnect
  7. AFAIK it is more popular and easier to get help with than vanilla web sockets, at least at the moment.

然而,就像有 VanillaJS 对于 jQuery 仇恨者一样,如果您更喜欢使用官方标准网络无论如何,直接使用套接字 API 将自己打倒.

However, just like there is VanillaJS for the jQuery haters, if you prefer using the official standard web socket APIs directly, by all means, knock yourself out.

这篇关于为什么要使用 Socket.io?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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