实时跟踪在线用户以进行两人测验

发布于 2024-11-18 15:35:21 字数 427 浏览 11 评论 0原文

我愿意创建一个两人实时问答游戏。为此,我需要跟踪用户何时进入我的测验页面以及何时离开。基本上,我需要某种大厅,玩家聚集在那里,我的脚本从那里随机挑选两个应该在游戏中面对面的玩家。

由于许多玩家会在很短的时间内从在线切换到离线,因此我不喜欢使用经典的“将玩家状态更新到数据库,然后以给定的时间间隔检索在线玩家列表”。目前,我正在考虑使用 Comet Push,并研究了一点 PubNub。

实际的问答游戏我相信它很容易解决:使用经典的 Cometpublish() 发送答案并 subscribe() 来检查其他用户的状态。但困扰我的是如何获得在线用户的特定列表?

我尝试在用户进入大厅时发布 user_id,但是当该用户离线时如何通知所有其他用户?如何在大厅中显示已连接用户的总数及其姓名?

这是我第一次面对彗星,它的逻辑对我来说并不完全清楚。

感谢您的帮助!

I am willing to create a two-player quiz game, in real time. For this I need to track when users are on my quiz's page and when they leave it. Basically, I need some kind of lobby, where players gather and from where my script picks two random players who should face each other in the game.

As many players would switch from online to offline in a very short time, I prefer not to use the classic 'update player status to database and then retrieve at a given interval the list of online players'. Currently, I am toying with the idea of using Comet Push, and have studied a little bit PubNub.

The actual quiz game I believe it is pretty easy to solve: use of classic Comet publish() to send answers and subscribe() to check the other user's status. But the thing that bothers me is how do I get that specific list with online users?

I tried to publish() a user_id when a user goes to the lobby, but how do I notify all the other users when this user goes offline? How do I display in the lobby the total number of connected users together with their names?

It's the first time I face Comet and its logic isn't entirely clear to me.

Thank you for your help!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

幸福不弃 2024-11-25 15:35:21

您可能想尝试 Pusher 和我们的(我为 Pusher 工作)在线状态功能。存在通道可让您轻松实现房间/大厅风格的功能,并且应该满足您的标准。

  • 当您订阅时,您会获得订阅该频道的用户的初始列表。
  • 每当用户订阅(进入)和取消订阅(离开)频道(房间/大厅)时,您都会收到通知,

这样您就不需要自己实现此功能。这是 Pusher 提供的解决方案的一部分。

You might want to try out Pusher and our (I work for Pusher) presence functionality. The presence channels let you easily implement room/lobby-style functionality and should meet your criteria.

  • You get an initial list of users subscribed to the channel when you subscribed
  • You are informed whenever a user subscribes (enters) and unsubscribes (leaves) the channel (room/lobby)

This way you don't need to implement this functionality yourself. It's part of the solution Pusher provides.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文