have multiple clients connect to a server using gamekit? (over bluetooth)

Discussion in 'iPhone/iPad Programming' started by stoopkitty, Mar 6, 2011.

  1. macrumors member

    Jan 26, 2010
    Like what would be the basic steps? Or does anyone know of any good tutorials?

    I have been trying to do some research on this online, and I think I have kind of got the idea, but i'm not completely sure what all of this does so could someone explain it? Also, I want to make sure it makes this connection over bluetooth, not WiFi, so is there a way to force it to do that. and i want one user to be the server and all of the rest to be clients (unless you think all of them being peers would be a better way to do this and you can tell me how to do it). and i cant use peer picker because it doesnt let you create your own interface.

    I think the basic steps are:

    1. ask the user whether they want to be a server or client
    2. server: initWithSessionID:displayName:sessionMode:GKSessionModeServer
    3. clients: initWithSessionID:displayName:sessionMode:GKSessionModeClient
    4. server: peersWithConnectionState:GKPeerStateAvailable
    5. server: use connectToPeer:withTimeout: for all of the possible peers that peersWithConnectionState:GKPeerStateAvailable found
    6. clients: have all of the other devices use acceptConnectionFromPeer:error:
    7. everyone: setDataReceiveHandler:self withContext:
    8. everyone: implement - (void) receiveData: (NSData *)data fromPeer: (NSString *)peer inSession: (GKSession *)session context: (void *)context; (in the same viewController class) and set it up to handle received data.
    9. everyone: use sendData:toPeers:withDataMode:error: or sendDataToAllPeers:withDataMode:error: to send data when i want to


Share This Page