Question about GameKit in Cabrera's "Beginning iPhone Games Development" book
Hi! I'm learning from Cabrera's book how to make networked games via Bluetooth using the Game Kit framework.
On page 564, the author mentions something that when certain statement inside the receiveData:fromPeer:inSession:context method gets called, we can be sure that the value inside the "myDiceRoll" variable already contains the results from our own roll attempt. I tried to make sense of that sentence by looking through GameKit's documentation but I don't understand how can we be 100% sure that "myDiceRoll" is valid. Isn't it possible that somehow we receive the data from the other device so fast that we don't to get to generate our own data?
I'm sure that many of you have read the book, so I'd be very thankful if you can enlighten me
Cheers,
--Nacho
On page 564, the author mentions something that when certain statement inside the receiveData:fromPeer:inSession:context method gets called, we can be sure that the value inside the "myDiceRoll" variable already contains the results from our own roll attempt. I tried to make sense of that sentence by looking through GameKit's documentation but I don't understand how can we be 100% sure that "myDiceRoll" is valid. Isn't it possible that somehow we receive the data from the other device so fast that we don't to get to generate our own data?
I'm sure that many of you have read the book, so I'd be very thankful if you can enlighten me

Cheers,
--Nacho
Figure 14-8 on page 558 shows why. In the algorithm, Player 1 rolls the dice and sends the message to Player 2 before checking for messages from Player 2.
Thanks for your reply!
Yes, I had looked at that diagram before posting but I wanted to know how that algorithm was reflected in the code. If you look at the code listing, the call to the diceRolled method is performed at the bottom of the peerPickerController:picker:didConnectPeer:toSession:. My question is: how can we be sure that the receiveData:fromPeer:inSession:context: method would never be called before we get to execute the [self diceRolled] statement? I think that the answer is related to the fact that this program is running in a single thread, but I'm not completely sure about it...
Cheers,
--Nacho
Yes, I had looked at that diagram before posting but I wanted to know how that algorithm was reflected in the code. If you look at the code listing, the call to the diceRolled method is performed at the bottom of the peerPickerController:picker:didConnectPeer:toSession:. My question is: how can we be sure that the receiveData:fromPeer:inSession:context: method would never be called before we get to execute the [self diceRolled] statement? I think that the answer is related to the fact that this program is running in a single thread, but I'm not completely sure about it...
Cheers,
--Nacho
You may want to ask on the book's forum.
http://iphonedevbook.com/forum
The author of the networking chapters has the username byteclub on the forum.
http://iphonedevbook.com/forum
The author of the networking chapters has the username byteclub on the forum.
Possibly Related Threads...
| Thread: | Author | Replies: | Views: | Last Post | |
| Is it possible to implement http connection for iPhone Development? | joyjit_b | 2 | 5,188 |
Aug 8, 2008 09:13 AM Last Post: Taxxodium |
|
| Beginning development | Hawksun | 28 | 10,304 |
Jun 16, 2002 04:44 PM Last Post: Carlos Camacho |
|

