使用蓝牙时,同一设备上是否可以有两个 GKSession 实例?
我正在编写多人游戏,并认为我会创建两个 GKSession 实例。一个会话设置为 GKSessionModeServer,另一个会话设置为 GKSessionModeClient。当我在客户端对等点上调用 peersWithConnectionState: 时,服务器会正确报告,并且每个会话都有不同的对等点 id。但是,当我尝试连接到服务器时,我收到消息 session:connectionWithPeerFailed:withError: ,错误描述为“挂起传出邀请时失败。”。
当 Wi-Fi 可用时,可以使用两个 GKSession。我担心蓝牙有一些限制不允许这样做,但我不确定。我可以重写代码以在服务器上使用单个 GKSession,但如果我知道其他人可以使用两个实例,我宁愿不编写特殊情况。
如果我关闭 Wi-Fi 和蓝牙,则会收到错误“网络不可用”。如果其中任何一个打开,我都不会得到。这让我相信,当附近有另一部 iPhone 时,它也不会工作。
I am writing mutliplayer game and thought I would create two instances of GKSession. One session set to GKSessionModeServer and the other to GKSessionModeClient. The server is properly reported when I call peersWithConnectionState: on the client peer and each session has different peer ids. But when I try to connect to the server I receive the message session:connectionWithPeerFailed:withError: with the error description "Failed while pending outgoing invitation.".
Using two GKSessions works when Wi-Fi is available. I am afraid that there is some limitation with Bluetooth that disallows this but I am not sure. I could rewrite the code to use a single GKSession on the server but I would rather not code special cases if I know that someone else got it working with two instances.
If I turn off both Wi-Fi and Bluetooth i get the error "Network not available." which I don't get if either is turned on. This makes me believe it won't work when there is another iPhone is nearby either.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我重写了代码,因此我只在托管设备上创建一个 GKSession,并直接在服务器和本地客户端之间发送数据,而不使用 GKSession。我终于可以用两个设备对此进行测试,并且它们可以正确地相互连接。因此,教训是主机上只有一个 GKSession,它将与蓝牙和 Wi-Fi 一起使用。
I rewrote the code so I only create one GKSession on the hosting device and send data between the server and the local client directly without using the GKSession. I could finally test this with two devices and they properly connect to each other. So the lesson is to have only one GKSession on the host and it will work with Bluetooth as well as Wi-Fi.