Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

GKSession Problems - Objective-C GameKit

Ok, I've been trying to create my own GKSession object and the delegate method is giving me an error in the console that I haven't figured out how to fix just yet. I was wondering if anyone had any suggestions or had encountered this problem? *Just a note - the variable peerStatus is defined elsewhere in my code. The peer can either be given a status of "kServer" or "kClient". I would rather define each to be in GKSessionModeServer or GKSessionModeClient because I've read that if the peer is in GKSessionModePeer, performance time is actually slower because it has to do the work of both Client and Server.

- (GKSession *)peerPickerController:(GKPeerPickerController *)picker sessionForConnectionType:(GKPeerPickerConnectionType)type {
    if (peerStatus == kServer) {
        GKSession *session = [[GKSession alloc] initWithSessionID:@"Josh_Land" displayName:nil sessionMode:GKSessionModeServer];
        return [session autorelease];
    }
    else {
        GKSession *session = [[GKSession alloc] initWithSessionID:@"Josh_Land" displayName:nil sessionMode:GKSessionModeClient];
        return [session autorelease]; 
    }
}

The whole error code is:

Listening on port 56386 2009-06-30 10:31:41.892 GKTank[17756:20b] *** Terminating app due to uncaught exception 'GKInvalidArgumentException', reason: 'A vaild GKSession object with a GKSessionModePeer mode must be supplied, or to create a default GKSession object return 'nil' in the implementation of -peerPickerController:sessionForConnectionType:. Supplied object was: sent 0 data packets : rush (0 packets 0 bytes): rely (0 packets 0 bytes) : rtry (0 packets 0 bytes) : sack (0 packets 0 bytes) : current weighted average rtt (0 ms) with session mode: 0' 2009-06-30 10:31:41.893 GKTank[17756:20b] Stack: ( 807902715, 2452446779, 807986683, 807986522, 927035842, 927037074, 927038407, 815223834, 927038949, 9245, 8562, 814709201, 815110321, 815119058, 815114270, 814813151, 814722763, 814748641, 839148405, 807687520, 807683624, 839142449, 839142646, 814752238 )

like image 965
Josh Bradley Avatar asked Jun 30 '09 14:06

Josh Bradley


1 Answers

I haven't actually implemented anything using GameKit yet, but just looking over the documentation, it looks like you can only use GKPeerPickerController if you are using GKSessionModePeer. If you want to use GKSessionModeServer/Client, you need to work directly with the sessions and their delegate. See the section in the Game Kit Programming Guide on Implementing a Server and Connecting to a Service.

Your main functionality would revolve around the GKSessionDelegate method
-session:peer:didChangeState: in both client and server modes and
-acceptConnectionFromPeer:error: and -denyConnectionFromPeer: in server mode.

like image 181
Martin Gordon Avatar answered Oct 03 '22 09:10

Martin Gordon