socket.io 与私人房间聊天
我开始研究node和socket.io。
我已经创建了一个简单的聊天应用程序,我惊讶于它是如此简单。
现在,我想更进一步,提供能够私下聊天的在线用户列表。
解决这个问题的最佳方法是什么?
我读过 0.7 的新房间功能。这是一条路吗?每次 2 个用户需要私聊时动态创建一个新房间?但是,如何通知第二个用户创建的新房间,以便他可以在那里进行连接?
自己处理上述所有逻辑是否更好?将房间和用户存储在服务器端并每次循环遍历它们并向适当的房间和用户发送消息?
谢谢
I started looking into node and socket.io.
I already have created a simple chat application and I am amazed at how easy it was.
Now, I would like to take a little bit further and provide a list of online users that have the ability to chat with each other in private.
What would be the best way to approach this?
I read on 0.7's new room feature. Would that be a way to go? Dynamically create a new room each time 2 users need to chat in private? But how the second user is going to be notified of the new room created, so that he can connect there?
Is it better to handle all the above logic myself? Store the rooms and users server side and loop through them each time and send messages to the appropriate ones?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
如果您想要的唯一功能是两个人能够互相发送消息(而不是一群人拥有一个房间),那么逻辑可能是这样的:
If the only functionality you want is for two people to be able to send messages to one another (and not groups of people to have a room), then the logic could be something like this:
Hej Thomas,
如果只有 2 个用户在说话,则不需要使用发布,只需将该消息从客户端发送到服务器,然后让服务器找到另一个客户端并将其发送下来。
Hej Thomas
if theres only 2 users talking you dont need use publish att all just send that message from the client to the server and let the server locate the other client and send it down.