I have a game, working with GameKit and using the Apple Game Center to manage the connection and messages.
When I am testing the software there is no issue with the connection, but once I am playing with another user over the internet the player is very often disconnected suddenly.
I would like to implement a simple method to reconnect the player or avoid to get the disconnected state from Game Center.
I was trying the solutions suggested at several forums and by the iOS documentation too, but all these are operating with sending a re-invite message to the user which is not really a nice solution.
I would like to have something like automatically waiting for the other user at least for 30 seconds or a minute before the game would tell that the player is disconnected finally.
Sometimes the disconnected message is coming very quickly after a normal data message, sent by the game itself, so it is not really clear why this happens.
Could someone has a good solution for this issue?
Related
There have been various other threads which touch on this topic, and many solutions offered - none of which ever actually work, so I figured I'd start again.
The problem, which started occurring on iOS 6, and has become chronic with iOS 8 is that Game Center will spontaneously disconnect players for no apparent reason. In my game I can have 2 to 4 players going and sending data to each other at a pretty good rate of 10-20 packets per second. The game will be running smoothly, and there's no sign of lost or delayed data. Yet all of a sudden one player will suddenly stop receiving or sending data, and then 20 seconds later it will timeout and disconnect from the game. This usually triggers a cascade which causes the remaining players to suddenly disconnect without warning.
In another thread someone thought the problem was caused by Reliable data packets - when one got lost Game Center would disconnect that player. This is not the case. I tried making all my data unreliable and it made no difference. Others have suggested it was caused by having Double NAT enabled on the router - not the case either.
Normally, this problem is sporadic, but in a new game we're working on it happens 100% of the time in a 3 or 4 player match, and occasionally in a 2-player match. It won't happen if all of the devices are in my office on WiFi. However, if I put one device on cellular it will fail every time. Or, if two devices are in the office on WiFi, and the other 2 are across the country on WiFi it'll fail.
Game Center clearly has issues, but this one is absolutely killing me. Has anyone made any progress in figuring out why Game Center will spontaneously lose connections with players even when things appear to be working just fine?
We have an game that creates a player lobby using sockets. When the player creates a lobby, a game is created on our server. Unfortunately if the user switches our app away with the Apple button, another user may join the game and the game will start with just one player active. So we want to send a message to our server via a socket when the app transitions to the background to close the lobby, stopping others joining.
But we can't. The sockets get frozen on entering background mode. Even if we keep the app alive a while using beginBackgroundTaskWithExpirationHandler, no socket activity works.
VOIP is not an option, as the title is not VOIP related and will get bounced immediately from Apple submission.
Any one got any non-VOIP related ideas?
Many thanks,
Steve.
I think what you want to do is to let the server know that this user is off-line when touching the Apple Home button.
I am using GCDAsyncSocket, but other ways may be similar.
What I'm doing is
Add observer on UIApplicationDidEnterBackgroundNotification.
When application enter background then call socket disconnect. The server will know that you are off-line.
I know this is a little late for your answer, but could be helpful for others.
I am finishing up an update to a 4 player Game Center enabled game and am suddenly having issues with spurious player disconnection messages that I did not have in the previous version. What is more odd is that not all devices connected to the match are receiving the message. One device will think the player is disconnected, but there is still messaging passing from the (supposedly) disconnected player to the other players.
These messages are coming straight from the match instance via match:player:didChangeState: messages so I don't think it would be anything in my code, but it doesn't make much sense. The game can progress for 10+ minutes with no problems and once one errant disconnect comes it, the rest fall out pretty quickly.
I have searched the web with every search term I can think of to see if others have seen this kind of behaviour and it appears that it is unique. It has to be something in my code, but I can't even think of how to get to the bottom of it.
Any help would be GREATLY appreciated,
Cameron
Make sure to call this:
//Finalize
[[GKMatchmaker sharedMatchmaker] finishMatchmakingForMatch:match];
After all players have connected. I was having this problem and it seems to have stopped the spurrious disconnects in my case.
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?
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!
I have a Application on a PC which displays time-information for a mp3 song that is played. I now need to display this time information within an iPad App. The counting timers for remaining time, player position and song length must be in sync between iPad an PC.
I thought about using a socket connection (AsyncSocket on iPad) to keep the counters in sync.
Is there a better way doing this? I don't want to run in the wrong direction...
Additional, it should be possible to have more than one iPad showing the Information in future. That's a "nice to have" feature...
I don't need ready to use code snippets, it's more a theoretical question. (if someone has a ready to use code snippet, that's also good for me :-) )
MadMaxApp
i now used the AsyncSocket to solve the requirements. It works perfectly. Don't forget the handling of closing the socket connection if the app goes in background. Depending on the server the app is talking with, not closing the socket can lead to a problem in reconnecting.