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.
Related
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?
I am developing a platform game trying to make it as well for multiplayer using the IOS Multipeer connectivity. I am stuck/confused/do not know what is the best way to send messages between peers (mostly like 4 peers in the game). The game style is like fun run and I have 4 hero running and firing each other and stuff like that. The thing is that keeping the positions of the other players is pushing me crazy!!
Sometimes other players are positioned in the wrong position (keeping in mind all devices are with the same screen size). Is that because of the lag of connectivity. How much information I can send per seconds and what is the best way to manage data transferring?
Any idea/thoughts are appreciated.
The throughput of MPC depends mostly upon the connection. What I've seen as the biggest performance problem is when one of the peers has WiFi disabled. This forces MPC to communicate over bluetooth which is incredibly slow. I've seen it run 20x slower than MPC over Wifi.
You don't need to be connected to a WiFi network. Just enable WiFi on all of the devices and iOS will leverage shared WiFi networks or create its own adhoc network.
The second thing you want to ensure is that your peers don't invite each other. You can only have one inviter in your network. When multiple peers invite and accept connections the MPC network become unstable.
Third thing is sendData:(NSData *)data toPeers:(NSArray *)peerIDs withMode:(MCSessionSendDataMode)mode error:(NSError **)error. If you are broadcasting your packets to all peers in the toPeers: array AND mode is MCSessionSendDataReliable then MPC waits until all of the connected peers ACK the message before moving on to the next packet.
UPDATE: I did some testing with my own app and over WiFi and two devices I can put about 100kbps. I'm using an iPhone 6 Plus and an iPhone 5S.
UPDATE 2: Thinking more about your question, there are a couple things to keep in mind with MPC communications:
Do all of your sendData and didReceiveData calls on a background thread and have that thread update your position data in your model. Tell your viewController that updates are available with a delegate method or notification.
Keep your data packets small, but design them so an update received represents the current state of your player. This allows you to miss an update and not be completely out of sync -- "send player 1 moved to (10, 10)" instead of "player 1 moved by (1, -1)"
Number your packets and use MCSessionSendDataUnreliable. If you get a packet with an earlier number than the last one you processed, throw it away. If you follow the second guideline above, you won't need this packet.
If you follow Dan Loughney's suggestions, I think your best bet in debugging is to log the received coordinates from the other players. That should help you identify whether the problem is due to timing issues, misinterpreted data or something else.
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?
In iOS6 I can specify the timeout that the next player must complete his turn, using this function:
endTurnWithNextParticipants:turnTimeout:matchData:completionHandler.
However, the timeout property doesn't exist in iOS5.
Since I want to support iOS5 as well, how can I specify that timeout in iOS5? Without this, the player can simply not play forever, and the game will be stuck without ending properly.
Thanks.
So far as I know, you are stuck if you’re supporting iOS 5.
One thing that might help is to use a local notification to remind a player to take their turn. (You’d cancel it when they do.) This won’t give quite the same user experience, but since most of your players will be on iOS 6, you could assume that at twice the timeout value, the iOS 5 player should have moved, and remind them to check on their current match.
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.