回合制游戏服务器的 websockets 和长轮询之间的差异 [英] Differences between websockets and long polling for turn based game server

查看:28
本文介绍了回合制游戏服务器的 websockets 和长轮询之间的差异的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在为 iOS 游戏编写服务器.该游戏是回合制的,服务器需要向客户端推送信息的唯一时间是通知对手的移动.

I am writing a server for an iOS game. The game is turn-based and the only time the server needs to push information to the client is to notify of the opponent's move.

我很好奇是否有人可以评论使用 WebSockets 和长轮询之间的性能和易于实现的差异.另外,如果我使用 WebSockets,我应该只用它来接收信息并发送 POST 请求来处理其他所有事情,还是所有的通信都应该通过 WebSocket 进行?

I am curious if anyone could comment on the performance and ease of implementation differences between using WebSockets and long polling. Also, if I used WebSockets, should I only use it to receive information and send POST requests for everything else, or should all communication be through the WebSocket?

此外,如果我也有兴趣制作 Web 客户端,在 WebSockets 和长轮询之间还有什么需要考虑的吗?

Additionally, is there anything extra to consider between WebSockets and long polling if I am interested in also making a web client?

推荐答案

对于其他可能想知道的人来说,它可能取决于事件之间的典型交互持续多长时间?

For anyone else who may be wondering, it could depends on how long typical interactions go between events?

Websocket:任何超过几十秒的时间,我认为保持 websocket 打开不是特别有效(更不用说 IIRC 如果应用程序失去焦点它无论如何都会断开连接)

Websocket: Anything more than a few tens of seconds, I don't think keeping a websocket open is particularly efficient (not to mention that IIRC it would disconnect anyway if the app loses focus)

长轮询:这迫使在服务器负载(现在有什么新东西?现在怎么样?...)和知道发生变化的速度之间进行权衡.

Long polling: This forces a trade-off between server load (anything new now? how about now? ...) and speediness of knowing a change has occurred.

推送通知:虽然这在技术上实施起来可能更复杂,但它确实是 IMO 的最佳解决方案,因为:

Push notifications: While this may be technically more complex to implement, it really would be the best solution IMO, since:

  • 几乎可以在事件发生后立即发送(和传递)通知
  • 没有 standby 服务器负载(来自开放的 websocket 或现在怎么样?"查询) - 随着您的使用基础的增长,这一点尤其重要
  • 您可以覆盖如果用户在应用内时收到通知会发生什么
  • the notification can be sent (and delivered) almost immediately after an event occurs
  • there is no standby server load (either from open websockets, or "how about now?" queries) - which is especially important as your use-base grows
  • you can override what happens if a notification comes in while the user is in-app

这篇关于回合制游戏服务器的 websockets 和长轮询之间的差异的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆