Gorm Lai
Gorm Lai

Reputation: 46

GKSession disconnects with more than 2 devices

We are using GKSession to setup a game. This works great with 2 devices, with one device being setup with GKSessionModeServer and the other GKSessionModeClient.

However, as soon as we have 2 or more clients (3 devices; 1 host and 2 clients) one of the clients will disconnect at random at some point. No error handlers are called (didFailWithError or connectionWithPeerFailed), only didChangeState on both server and client. The disconnect usually happens within a minute, sometimes much less.

All devices (2 iPhones and 1 Simulator) are on the same wireless network. One physical device runs iOS6.0.1, and the other 5.1.1, and both can keep connected when connecting to the simulator. It is only with 3 devices (2 real, 1 simulated) that the problem happens.

Any help would be great appreciated.

Upvotes: 1

Views: 350

Answers (1)

mastergap
mastergap

Reputation: 375

I have the same problem but in my app this problem happens when i connect the third or the forth client (randomly). The server gets the disconnection event, but the client freezes. I noticed that is always the last client connected being disconnected few seconds later. I can't understand How to solve the problem, i found an app called idea flight that manages client/server connections through gamekit and that can manage up to 15 clients (as specified in GameKit documentation), i tested it and it works. It's 3 days that i'm losing my mind on the code, and i'm thinking about switching to standard socket communication, but i will lose Bluetooth support.

EDIT: I found the reason of the problem. This problem happens when the network is composed by a mix of devices running both iOS 6 and previous iOS versions. If the network is composed only by devices running iOS6 or only previous versions everything is fine. More precisely this isn't a crash, but the client that gets stuck has some threads that are waiting on a mutex, which means that the GameKit leads our app to a deadlock. Reading on the Apple Developer's Forum I've known that some users have reported this bug directly to Apple, but Apple didn't answer to them. So, for now, the only way to ensure apps based on GKSession to run safely is to support only iOS 6 or to write a network communication system from scratch with Bonjour, sockets and low level BlueTooth API.

Upvotes: 3

Related Questions