定义 GKSessionModeServer 和 GKSessionModeClient

发布于 2024-12-16 13:01:08 字数 322 浏览 1 评论 0原文

我的问题是,我必须使用 GameKit 框架连接许多设备。 两个连接一切正常(GKSessionModePeer) 我在互联网上搜索了很多关于如何连接两个以上设备的信息,我得到的是使用 GKSessionModeServer 和 GKSessionModeClient 。我还阅读了苹果文档。

但对于如何使用 GKSessionModeServer 和 GKSessionModeClient 意味着哪个设备将充当服务器、哪个设备将充当客户端,仍然没有任何明确的解决方案。

如果有人知道如何处理这个问题或我应该采取什么方法,请告诉我。

任何帮助将不胜感激。

My problem is that , I have to connect many devices using GameKit framework.
Everything works fine with two connections(GKSessionModePeer)
I searched a lot on internet on how to connect more than two devices and what I got is, to use GKSessionModeServer and GKSessionModeClient.I read the apple documentation also.

But still there is not any clear cut solution on how to use GKSessionModeServer and GKSessionModeClient means which device will act as server and which will act as client.

Please if any one know how to handle this or what approach should I follow, tell me.

Any help would be highly appreciated.

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

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

发布评论

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

评论(1

少钕鈤記 2024-12-23 13:01:09

我没有在游戏中使用 3 台设备进行尝试,但也许这会对您有所帮助(它适用于大厅中的 5 台设备)。

  1. 我不使用 GKSessionModeServer/Client,我使用 GKSessionModePeer。
  2. 我会自动连接 - 这意味着当新设备出现时,其他设备会向它发送连接请求,并且它会自动接受(因此,如果我们打开了 3 个设备,则所有设备都会连接在一起)
  3. 一旦连接了所有设备,您就可以如果您有足够的玩家,可以通过发送正常数据包(I_INVITE_YOU、INVITATION_DECLINED、INVITATION_ACCEPTED)来发送虚假邀请,然后断开其他设备的连接。您可以将断开连接的设备添加到您的临时忽略列表中 - 如果用户返回主菜单或其他东西,则将其重置
  4. 一旦您的所有队伍都在游戏中,他们就可以决定谁是谁:
  5. 如果您的游戏不发送大量数据,您可以对 udid 或peerid 进行一些简单的检查:假设 udid 最低的设备是服务器,其他设备是客户端
  6. 如果您的游戏发送大量数据,我发现服务器应该是最慢的机器 - 问题是当服务器速度很快时(假设 50fps 工作),它以类似的帧速率发送数据,因此当客户端速度较慢时(假设 20fps),它每帧从服务器获取大约 2 个数据包,这进一步减慢了速度。问题是如何确定哪个设备最慢。我使用平均 fps,

听起来有点复杂,但比标准 ios 邀请方案效果好得多(这是 3.1 的痛苦经历)

问候!

I didnt try it with 3 devices ingame, but maybe this will help you (it worked with 5 devices in lobby).

  1. I dont use GKSessionModeServer/Client, I use GKSessionModePeer.
  2. I do autoconnect - it means that when new device shows up, other devices send connect request to it and it gets accepted automatically (so if we have 3 devices turned on, all of them are connected together)
  3. Once you have all devices connected, you can send fake invitiations by sending normal data packets (I_INVITE_YOU, INVITATION_DECLINED, INVITATION_ACCEPTED) and then disconnecting other devices if you have enough players. You can add devices that disconnected you to you temporary ignore list - reset it if user goes back to main menu or sth
  4. Once you have all the party ingame, they can decide who is who:
  5. If you game doesnt send lots of data, you can do some simple checks against udid or peerid: lets say device with lowest udid is the SERVER, others are CLIENTS
  6. If your game sends tons of data, I've observed that server should be THE SLOWEST machine - the thing is that when server is fast (works with lets say 50fps), it sends data at similar framerate, so when client is slow (lets say 20fps), it gets about 2 packets from server per frame, which further slows it down. Question is how to decide which device is slowest. I used average fps

it sounds a bit complicated but works much better than standard ios invitation scheme (it was traumatic experience with 3.1)

Regards!

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