将 Pusher/Pubnub 与权威游戏服务器结合使用
我想构建一个 2 人回合制游戏,并使用权威服务器来管理游戏状态/逻辑。我想到的流程是这样的:
- 玩家订阅一个独特的游戏频道(通过 pubnub/pusher/类似的东西)
- 玩家通过 HTTP 直接将他们的回合提交到游戏服务器
- 服务器运行游戏逻辑并将结果发布到游戏的频道(两个玩家都订阅了)
- 客户端处理响应并呈现结果
- 匹配有点让我困惑。有什么建议吗?
这是在这种情况下使用发布/订阅服务的“正确”方式吗?有没有更好的方法(除了不断轮询服务器之外的其他方法)?
I'd like to build a 2-player turn based game with an authoritative server to manage the game state/logic. The flow I have in mind is something like:
- Players are subscribed to a unique game channel (via pubnub/pusher/something similar)
- Players submit their turns over HTTP directly to the game server
- The server runs the game logic and publishes the result to the game's channel (which both players are subscribed to)
- The client handles the response and renders the outcome
- matchmaking kind of confuses me though. Any suggestions?
Is that the "right" way of using a pub/sub service in this scenraio? Is there a better approach (something other than polling the server constantly)?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这是我们办公室的热门话题!我一直使用 PubNub 作为权威的游戏服务器,并创造性地选择频道名称。它的工作原理如下:
This is a heated topic at our office! I've been using PubNub as an authoritative game server using creative choice of channel names. It works like this:
你的建议听起来不错,而且是“正确”的方式。您面临的挑战从计算机时代开始就一直存在,其中同步数据是移动智能手机等多个设备之间的要求。轮询速度慢且成本高(对于大量玩家来说没有意义)。多人游戏就是一个很好的例子,需要配对玩家并提供游戏室。您的解决方案是:
您可以使用 Socket.IO 等产品和其他一些开源选项来解决此技术挑战。然而,您只想构建游戏,而不是专注于部署 Node.JS 服务器并将其连接到 Express。
请改用 PubNub、PusherApp 或 Beacon Push 等云服务。利用 Pub/Sub API 轻松同步多人游戏环境中的用户。
Your proposal sounds great and is the "right" way. The challenge you face is shared from the beginning of the computer epoch, where synchronizing data is a requirement between multiple devices such as a mobile smartphone. Polling is SLOW and expensive (and does not make sense for a large number of players). Multiplayer games is a great example need to pair players and provide game rooms. Your solution is to:
You may solve this technical challenge with products such as Socket.IO and some other open source options. However you want to just build your game rather than focus on deploying a Node.JS server and hooking it up to Express.
Instead use a Cloud Service like PubNub, PusherApp or Beacon Push. Utilize the Pub/Sub API to synchronize users in a multiplayer environment easily.