1

I'm using GKSession in the Peer mode where an instance of the app is both a server and client.

I connect to other peers like this:

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state {
    self.currentSession = session;

    if (state == GKPeerStateAvailable) {
        [session connectToPeer:peerID withTimeout:0];
    }
}

- (void)session:(GKSession *)session didReceiveConnectionRequestFromPeer:(NSString *)peerID {
    [session acceptConnectionFromPeer:peerID error:nil];
}

If I have one device running the app and then start another device running the app, both devices will see each other and send -connectToPeer:withTimeout:.

What I don't understand is if it would be sufficient that only one of two devices that wish to connect with each other sends a connectToPeer:withTimeout: request if a two-way communication is needed.

And then, I fear the bidirectional connection request can cause trouble. Is this OK to to it blindly like this or must I employ more sophisticated checks so only one connection between a pair of peers is made?

Edit: Test revealed that it is enough of ONE peer connects to the other peer. Also tested that each peer will see the other peer becoming available. So my code above will make one superfluous connection request. The question remains if this is harmful for the stability and capacity of the network.

openfrog
  • 40,201
  • 65
  • 225
  • 373

0 Answers0