Javascript node.js 多房间聊天示例

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/3409589/
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-08-23 04:30:51  来源:igfitidea点击:

node.js multi room chat example

javascriptnode.jswebsocket

提问by Mark

I'm looking for a websocket/node.js chat implementation which supports multiple rooms.

我正在寻找支持多个房间的 websocket/node.js 聊天实现。

I'm also going to write an app which needs multiple rooms or servers, and I'm just looking for some code samples of how people do it.

我还将编写一个需要多个房间或服务器的应用程序,我只是在寻找人们如何做的一些代码示例。

Thanks.

谢谢。

I know there's a service http://pusherapp.comwhich provides this service, but I'm looking for an open source example.

我知道有一个服务http://pusherapp.com提供此服务,但我正在寻找一个开源示例。

采纳答案by Shripad Krishna

I realized that you have not yet received a solution to your issue yet. Suggest looking at this question where i have provided the answer:

我意识到您还没有收到问题的解决方案。建议看看这个问题,我已经提供了答案:

node-websocket-server: possible to have multiple, separate "broadcasts" for a single node.js process?

node-websocket-server:单个 node.js 进程可以有多个单独的“广播”吗?

回答by Michael Moeller

tested and working great:

经过测试并且运行良好:

https://github.com/mmukhin/psitsmike_example_2

https://github.com/mmukhin/psitsmike_example_2

(node.js and socket.io multiroom chat tutorial with 17 stars on github)

(node.js和socket.io多房间聊天教程,github上17颗星)

回答by Daniel Beardsley

Womptis an node.js multi-room chat server that was recently open-sourced.

Wompt是一个最近开源的 node.js 多房间聊天服务器。

回答by Matt Kneiser

Socket.io has support for rooms. This link helped me implement them in a matter of seconds.

Socket.io 支持房间。此链接帮助我在几秒钟内实现它们。

https://github.com/LearnBoost/socket.io/wiki/Rooms

https://github.com/LearnBoost/socket.io/wiki/Rooms

回答by skrat

You can take a look at http://orbited.org/running STOMP protocol (http://stomp.codehaus.org/Home). It has channel support (your rooms). So you just need to send some JSON encoded messages carrying user's nicknames to a channel. I'm not sure how to get the list of channels, might be that you need to track these yourself.

您可以查看运行 STOMP 协议的http://orbited.org/( http://stomp.codehaus.org/Home)。它有频道支持(你的房间)。因此,您只需要向频道发送一些带有用户昵称的 JSON 编码消息即可。我不确定如何获取频道列表,可能是您需要自己跟踪这些频道。

回答by Nikolaus Gradwohl

There is a really nice tutorial by laktekthat shows how to use websockets with node.js. He has also a colaborative code editor that uses redisas a backend of a pub/sub service described here

laktek有一个非常好的教程,展示了如何在 node.js 中使用 websockets。他还有一个协作代码编辑器,它使用redis作为此处描述的发布/订阅服务的后端

回答by MKroehnert

There is this Gistavailable from Ryan Dahl the author of Node.JS which is a basic IRC daemon written in Node.JS. It is featured in this blog postwhich describes several IRC related Node.JS programs. Together with websocket this might be an alternative to try out.

此要点可以从瑞安达尔的Node.js的作者是写在Node.js的一个基本的IRC守护进程 它在这篇博客文章中有特色,它描述了几个与 IRC 相关的 Node.JS 程序。与 websocket 一起,这可能是尝试的替代方法。

The webchat demo (http://chat.nodejs.org/)hosted on the Node.JS homepage is a complete example and the source code can be found in the following GitHub repositoryand is available under the MIT license.

Node.JS 主页上托管的网络聊天演示 (http://chat.nodejs.org/)是一个完整的示例,源代码可在以下 GitHub 存储库中找到,并在 MIT 许可下可用。

回答by Mark

http://github.com/maccman/juggernautThere's this one, only for ruby though.

http://github.com/maccman/juggernaut有这个,不过只适用于 ruby​​。