为什么要使用 Socket.io?

编程入门 行业动态 更新时间:2024-10-27 20:24:13
本文介绍了为什么要使用 Socket.io?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我正在学习 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?

推荐答案

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

更多推荐

[db:关键词]

本文发布于:2023-04-26 05:39:59,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1130452.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:要使   Socket   io

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!