简体   繁体   English

Express,ws,websocket,express-ws

[英]Express, ws, websocket, express-ws

I'm writing server-side for my project and it requires features websockets provides. 我正在为我的项目编写服务器端,它需要websockets提供的功能。 I've been searching and found 3 libraries in npm. 我一直在搜索并在npm找到3个库。 ws, websocket and express-ws. ws,websocket和express-ws。 Can you please explain the difference between them and give the pros and cons for each? 你能否解释一下它们之间的区别,并给出各自的利弊?

I'm using Express in my project. 我在我的项目中使用Express。 Is it okay that I'm using REST API and websockets simultaneously? 我可以同时使用REST API和websockets吗?

I can't give you the full answer. 我不能给你完整的答案。

if you search from npm, the famous websocket libraries are socket.io and ws. 如果你从npm搜索,着名的websocket库是socket.io和ws。 Both of them hit more than 4 millions download per month. 他们两个月每月下载量超过400万。

Many people use socket.io because of the rich features, but you may be overwhelming when you are studying it. 很多人使用socket.io是因为它具有丰富的功能,但是当你学习它时,你可能会感到压倒一切。

ws is my favorite, and many people may consider it as a simple and easy solution. ws是我最喜欢的,许多人可能会认为它是一个简单易用的解决方案。 In fact, the express-ws library that you mention is built on top of ws. 事实上,你提到的express-ws库是建立在ws之上的。

I created a library which built on top of ws as well. 我创建了一个建立在ws之上的库。 You can try it out. 你可以尝试一下。 Super easy to use. 超级好用。 It supports both node.js and client-side. 它支持node.js和客户端。 Websocket can be created easily, and the library will handle the websocket and reconnect itself when dropped. 可以轻松创建Websocket,并且库将处理websocket并在删除时重新连接。 Check the example folder or run it to see the effect. 检查示例文件夹或运行它以查看效果。

wsm - WebSocket Manager wsm - WebSocket Manager

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

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