Search code examples
iosnetwork-programminggamekitgksession

Gamekit Latency


I have the following problem with GKSessions: Sometimes there is a huge delay when sending data (3-4 seconds sometimes up to 10 seconds) in a client/server application.

If the server sends let's say 10 packets during the delay, those 10 packets are received all at once on the client. The weird thing is that the server still receives packets from the clients during the delay.

This delay seems to be worse in WiFi networks but also happens in bluetooth networks.

Did anyone else encounter such delay spikes when using gamekit? What could be the source of this issue?


Solution

  • I've been working a lot with gamekit and gksession. I always use the Peer2Peer mode even though some people discourage it. I never experience any kind of delay like the one you describe.

    Do you send with GKSendDataReliable or GKSendDataUnreliable? Try switching to the other and see if it changes anything. If you're using GKSendDataReliable then the sending device will wait for a "Received" message from the receiver before sending the next message. This might be the problem.

    On your testing devices: Is anything running which might flood the network?

    I was testing a multiplayer gamekit based game, and if I had several active devices then suddenly some would stall completely, and I needed to hard reboot (shut down completely and restart) them to make them work again.

    If you keep getting in trouble you might want to try a much more low level api: dns-sd https://developer.apple.com/library/mac/#documentation/Networking/Conceptual/dns_discovery_api/Introduction.html

    I hope you make it work, good luck!