ios - 优化 4 人对等网络拓扑

标签 ios networking sprite-kit multiplayer gamekit

我正在使用 Sprite Kit 和 Game Kit 开发实时游戏。该游戏具有多人游戏模式,4 名玩家可以一起玩。我一直在阅读 Game Kit 编程指南并发现以下段落:

Although the GKMatch object creates a full peer-to-peer connection between all the participants, you can reduce the network traffic by layering a ring or client-server networking architecture on top of it. Figure 8-1 shows three possible network topologies for a four-player game. On the left, a peer-to-peer game has 12 connections between the various devices. However, you could layer a client-server architecture on top of this by nominating one of the devices to act as the host. If your game transmits to or from the host only, you can halve the number of connections. A ring architecture allows devices to forward network packets to the next device only, but further reduces the number of connections. Each topology provides different performance characteristics, so you will want to test different models to find one that provides the performance your game requires.

enter image description here

这就是我感到困惑的地方。目前,在我的游戏中,我已经实现了点对点拓扑,其中每个用户将他们的位置发送给游戏中的每个其他玩家。最终总共发送了 12 条消息,因为每个玩家发送了 3 条消息。

但是根据文档,如果我在游戏上分层客户端-服务器拓扑,我可以通过减少连接数量来减少网络流量。如果我这样做,那么每个客户端都会将其位置发送给主机,然后主机需要将这些位置转发给其余的客户端。因此,现在一名玩家(主机)需要额外工作,因为客户端不再相互通信。然后我们仍然得到 12 条消息。主机发送 9 条消息(每个玩家 3 条消息,加上 6 条用于中继其他客户端位置的消息),然后每个客户端向主机发送 1 条位置消息。 9 + 1 + 1 + 1 = 12 条消息。这是有道理的,我们所做的只是不均匀地分配消息发送,所以现在一个玩家需要更加努力地工作来弥补其他玩家所做的较少的工作。

此外,中继客户端消息需要额外的时间,因为每个客户端的位置现在都需要通过主机。

因此,虽然现在连接较少,但一个玩家发送的消息较多(9 条消息),而不是每个玩家均匀分配工作负载(即每个玩家发送 3 条消息)。这似乎会导致发生断线的可能性更大,因为主机更容易从比赛中断线。

那么有人可以向我解释一下如何通过分层客户端-服务器拓扑来减少网络流量吗?即使总体消息相同,比赛中连接数较少是否会减少网络流量?请记住,这里没有专用服务器,我(和文档)正在谈论在对等匹配之上分层客户端-服务器拓扑。另外,主机断开连接的可能性是否更大,因为他发送的消息数量是其他玩家的 3 倍。毕竟,GKMatch 会在短暂丢包后断开玩家的连接。或者仅仅是因为拥有 12 个连接,因此由于流量增加而导致断开连接的可能性更大?

最佳答案

我很抱歉对一个描述性很强且写得很好的问题给出了非常简短的回答,但答案很简单。服务器(您使用了术语“主机”,但这很令人困惑)不必向每个客户端发送 3 条单独的消息。服务器收集所有信息并仅向每个客户端发送一条包含所有信息的消息。

关于ios - 优化 4 人对等网络拓扑,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29785106/

相关文章:

linux - 如何在 linux 中基于 tcp 选项字段丢弃数据包

python - Redis、Python 通过网络发送消息

swift - 物理速度导致 parent 与 child 分离

ios - 构建后 XCode iOS 颜色不匹配

ios - 由于 "Launch storyboard not found"(ERROR ITMS-90705),无法将项目上传到 App Store

ios - 传递滞后于一个 UIAction 按钮的值

C - 套接字 - 连接 :result too large (windows)

swift - 触摸 Sprite,使其跳起来然后再次落下(重复点击 spritenode 的次数。)

sprite-kit - 如何检测物理体不同区域的接触

ios - 在独立 View 中使用时,iOS 8 中屏幕边缘的 UIBarButton 项目