I have created a card game using GameCenter and the Real Time server-client networking strategy. While testing in the sand box, the game works flawlessly (makes the connection, picks the best host, sends/receives data) and sometimes the game actually even completes without an issue. However, MOST of the time, on both devices I will receive a match:player:didChangeState: callback informing me that the opposing user has disconnected. It happens frustratingly often, and does not seem to have anything to do with inactivity or a timeout. My thoughts are I may be dealing with normal network latency on the GameCenter servers, since there were rare cases where the player seems to reconnect and sends data again. Is anyone else dealing with these issues using GKMatch and Real Time GameCenter? I am testing the app on an iPhone 5 and iPhone 4 both running iOS 6.1 and connected to the same wifi network.
I have created a card game using GameCenter and the Real Time server-client networking
Share
While I didn’t find an exact solution for the disconnects, I patched my problem with the following. Also, to prevent losing messages sent during a disconnect: I implemented a “response” handler that detects whether the message was actually received by the opponent (since the Reliable data send mode does not error out when a message isn’t received by the opponent due to connection issues).
When the game is started, I determine a user to be the host (chooseBestHostPlayerWithCompletionHandler:^), and when I detect a disconnect the host player re-invites the non-server player back to the game. This works whether the game was started by invitation OR “Play Now”. It solved my issue of the “ShouldReconnect” which only works with 1v1 and Invitation matches. When the non-host player accepts the invite, I complete the matchmaking programmatically to prevent the MatchMakerViewController from having to appear omn screen. Once reconnected the match resumes without issue.