Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.

glenncal

macrumors member
Original poster
Jun 7, 2009
80
0
I am currently creating a Game Center game, and am using the peer-to-peer functionality available. However, I would like to select one of the players (2 players) to act as a host, to ensure synchronization.
What is the best way to select a host (even randomly) from the players available and ensure that the other device knows which host was chosen?
 
Last edited:
I am currently creating a Game Center game, and am using the peer-to-peer functionality available. However, I would like to select one of the players (2 players) to act as a host, to ensure synchronization.
What is the best way to select a host (even randomly) from the players available and ensure that the other device knows which host was chosen?

Old school method is to for each to choose a random number prior to negotiation. Highest number when they connect becomes the host. You can also then bias the random number method to rank the more capable device higher - such as iPhone 4 ranks higher than iPod 3rd Gen, but not higher than iPad 2. Build in future proofing by setting the bias to a high number and then lowering it to values based on known devices.
 
Thank you :) I'd been trying to find a persistent player id to compare, so I never came close to thinking this.
 
Very smart, that will do me nicely!

Old school method is to for each to choose a random number prior to negotiation. Highest number when they connect becomes the host. You can also then bias the random number method to rank the more capable device higher - such as iPhone 4 ranks higher than iPod 3rd Gen, but not higher than iPad 2. Build in future proofing by setting the bias to a high number and then lowering it to values based on known devices.
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.