iPhone P2P - is GKSession unreliable beyond 4 peer

2020-07-27 16:15发布

问题:

Original question: The iOS Developer Library mentions in the Game Kit Programming Guide that

The maximum size of a client-server game is 16 players.

Does this limitation also apply to P2P GKsessions?

This was already kind-of asked here (but from a different angle).

Updated question:Is GKSession reliable when more than 4 peers are connected?

note:The question was updated based on the response by saulobrito below.

Reference: One example of an app that uses a large group of peers connected is Seedio. You will notie that they are not using GKSession as bluetooth is not an option for connectivity (with GKSession, you can't even chose bluetooth or wi-fi.. GKSession does that for you.) Check out their FAQ for some interesting information about why they chose Wi-fi rather than bluetooth.

回答1:

What I can assure you is that GKSession is very unstable and you should not trust these docs. In fact, Apple recently decided to remove the documentation altogether.

I did a lot of testing and I would suggest that the practical limit is 4 connected devices (one acting as a server and 3 clients). Of course it's better that you do your own testing scenario.

I also couldn't find any game that allows more than 4 players. The only that I knew was Apple own Texas Hold'em - which allowed 8 players, but they decided to remove it.

And last, but not least, Game Center imposes a 4 player limit to peer-to-peer games.

Yes I'm developing a game that should support 10 players but, in our tests, it became unstable/unusable when there were more than 4 devices. By unstable I mean: sometimes you can't find a peer and connection drops in less than a minute. To make matters worse, updating to iOS 6 brought some strange behaviors like freezing (no error, no stack trace, no nothing) while trying to send a message. Other odd thing: when a player loses connection, all other players get disconnected.

EDIT: did a lot of testing since that response and have more information to share:

Using iOS 6 I was able to play reliably with 9 devices using either wi-fi or bluetooth. There's stil a huge issue although: You can't connect devices using iOS 6 with devices using iOS 5 cause you will face unexplainable freezing-with-no-stack-trace time to time if any of the devices is with its wi-fi enabled. You either set iOS 6 as the minimum supported version for your App or you will have to ask users to disable their wi-fi and use bluetooth.



回答2:

On iOS 6.0 I can confirm that GKSession allows at least 6 players. I have found that you must make sure not to send messages to a peer until the state changes to connected though.

Overall, I think GKSession is a wonderful and simple API. It will use bluetooth or WiFi, meaning that you don't even have to think about whether the phone is connected to a WiFi network. The latency is nice and low ( I measured it at 4ms for unreliable and around 10ms for reliable networking ).

My main caveats are:

  1. Use unreliable messaging if you can.
  2. Make sure you set .available to NO on application exit ( if you're terminated while advertising, you may leave phantom sessions open ).
  3. Do not try and send messages to a peer until the peer in question changes to the connected state.
  4. Don't try to re-use a gksession once you've been disconnected.
  5. You may need to retry a connection attempt ( I automatically retry 3 times if a connection attempt fails ). My timeout is 10 seconds.
  6. Throttle your reliable messaging. I haven't quite figured out what the limit is, but eventually it seems like you will blow a transmission buffer and then your latency will balloon. Again, this just isn't a problem when you use unreliable messaging.