node.js engine.io 和 socket.io 有什么区别?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8542502/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 14:54:32  来源:igfitidea点击:

What's the difference between engine.io and socket.io?

node.jssocket.io

提问by L N

Please correct me if this question is a duplicate. Regarding node.js, I'm using socket.io for real-time socket connection from the client application to the server application. I just heard about engine.io, is engine.io a replacement for socket.io? I could not find any useful information on engine.io website

如果这个问题是重复的,请纠正我。关于 node.js,我使用 socket.io 进行从客户端应用程序到服务器应用程序的实时套接字连接。我刚刚听说engine.io,engine.io 是socket.io 的替代品吗?我在 engine.io 网站上找不到任何有用的信息

Thanks in advance

提前致谢

回答by Raynos

engine.iois a lower level library than socket.io.

engine.io是一个比 socket.io 低级的库。

Engine is to Socket.IO what Connect is to Express.

Engine 之于 Socket.IO 就像 Connect 之于 Express。

If you want the lower level abstraction, use engine.io. If you want a websocket abstraction, keep using socket.io.

如果您想要较低级别的抽象,请使用 engine.io。如果你想要一个 websocket 抽象,继续使用 socket.io。

engine.io is of more interest to you if you're building a library/framework on top of socket.io.

如果您在 socket.io 之上构建库/框架,那么您对 ​​engine.io 更感兴趣。

socket.io is of more interest to you if you're building an application on top of socket.io.

如果您在 socket.io 之上构建应用程序,那么您对 ​​socket.io 更感兴趣。

回答by kidcapital

socket.io is built on top of engine.io.

socket.io 建立在 engine.io 之上。

socket.io is engine.io with bells and whistles.

socket.io 是带有花里胡哨的 engine.io。

if you don't need everything socket.io has (redis store, groups, etc.) just use engine.

如果您不需要 socket.io 的所有内容(redis 存储、组等),请使用引擎。

回答by khoomeister

A bit late to the game :-), but I'll mention it here for posterity.

游戏有点晚了:-),但我会在这里提到它以供后代使用。

Aside from being "lower level", one of the most important differences is socket.io will start with websockets first & degrade until it finds a transport that can work. On the other hand, engine.io will start with short polling (and upgrade on the side until it hits a wall).

除了“较低级别”之外,最重要的区别之一是 socket.io 将首先从 websockets 开始并降级,直到找到可以工作的传输。另一方面,engine.io 将从短轮询开始(并在侧面升级,直到碰壁)。

Why?

为什么?

From the user perspective, an unsuccessful WebSocket connection can translate in up to at least 10 seconds of waiting for the realtime application to begin exchanging data. This perceptively hurts user experience.

从用户的角度来看,一个不成功的 WebSocket 连接可能会导致等待实时应用程序开始交换数据的时间至少为 10 秒。这在感知上损害了用户体验。

At the moment (2013), websockets isn't pervasive yet (e.g. older browsers, cellular networks, etc.) so it's smart to start with the XHR 1st.

目前(2013 年),websockets 尚未普及(例如较旧的浏览器、蜂窝网络等),因此从 XHR 1st 开始是明智之举。

See https://github.com/LearnBoost/engine.io(Goals section) for more info.

有关更多信息,请参阅https://github.com/LearnBoost/engine.io(目标部分)。

回答by Deniz Ozger

Socket.IO v0.9 is outdated and a bit buggy, and Engine.IO is the interim successor. Socket.IO v1.0 (which will be released soon) will use Engine.IO and be much better than v0.9.

Socket.IO v0.9 已经过时并且有一些问题,Engine.IO 是临时继任者。Socket.IO v1.0(即将发布)将使用Engine.IO,比v0.9好很多。

In my tests, Engine.IO appeared to perform better than Socket.IO v0.9, see the comparison: https://medium.com/node-js-javascript/b63bfca0539

在我的测试中,Engine.IO 的性能似乎比 Socket.IO v0.9 更好,请参见比较:https://medium.com/node-js-javascript/b63bfca0539

Socket.IO tries to reconnect for some time after connection is lost, whereas Engine.IO does not.

Socket.IO 会在连接丢失后尝试重新连接一段时间,而 Engine.IO 不会。

Socket.IO supports rooms whereas Engine.IO does not. You would need rooms (either via these modules or your own implementation) if you'll have connections listening to different data/channel.

Socket.IO 支持房间,而 Engine.IO 不支持。如果您有连接侦听不同的数据/通道,您将需要房间(通过这些模块或您自己的实现)。