GKSession sendDataToAllPeers including sender?
I've got a number of devices connected over wifi using GameKit. I have a simple UIAlertView
popping up when peers (clients) receive data. All but the sender (server) show this alert view when data is sent, so I'm wondering if that's a bug in my app or if that's expected behavior. If the device doing the sending is also a GKSessionModePeer
, I would expect it to "fire" its receiveData:
message as well since I'm sending to all peers.
Should I call a method manually at the same on the sender device? For example, if I wanted to send a开发者_运维知识库 "GameStart" packet to the 4 phones, the peers would call startGame:
in the receiveData:fromPeer:inSession:context:
method when it receives that packet and the sendee would be calling sendDataToAllPeers:
and call startGame:
on itself.
Does that sound right or is there a way to include the sender in the sendDataToAllPeers:
list so that it responds exactly the same as all connected peers?
I presume by sendee you mean sender, ie. the one sending the data. (Sendee = the intended recipient, which in your case is everyone).
That's expected behavior. "All peers" doesn't include the sender, and you can't currently include the sender in the sendDataToAllPeers: list. Your plan of calling a method manually on the sender device at the same time as you send the message to the peers sounds like the best way to go.
If you want to be sure the data went out OK before you do something on the sender, you could send back an acknowledgment from the peers.
精彩评论