tags:

views:

930

answers:

1

Hello,

I want to connect two devices using the GKSession, starting one as a server and the other one as a client. Using this configuration I can't use the GKPeerPickerController.

I'm having problems for connecting the two devices:

  • Using only bluetooth: impossible
  • using WiFi: at least there are some data exchange between the devices but no successfully conection.

In the interface file I have the

GKSessionDelegate
GKSession *session;

In the implementation, I start the server using this code:

session = [[GKSession alloc] initWithSessionID:@"iFood"  displayName:nil sessionMode:GKSessionModeClient];
session.delegate = self;
session.available = YES;

The client starts using this code:

session = [[GKSession alloc] initWithSessionID:@"iFood"  displayName:nil sessionMode:GKSessionModeServer];
session.delegate = self;
session.available = YES;

How I can force the use of Bluetooth instead of the WiFi ?

Also I have implemented those calls:

-(void)session:(GKSession *)session didReceiveConnectionRequestFromPeer:(NSString *)peerID {
NSLog(@"Someone is trying to connect"); 
}

- (BOOL)acceptConnectionFromPeer:(NSString *)peerID error:(NSError **)error {
NSLog(@"acceptConnectionFromPeer");
}

When I start, I get this into the debugger:

Listening on port 50775
2010-02-19 14:55:02.547 iFood[3009:5103] handleEvents started (2)

And when the other device starts to find, I get this:

~ DNSServiceBrowse callback: Ref=187f70, Flags=2, IFIndex=2 (name=[en0]), ErrorType=0 name=00eGs1R1A..Only by Audi regtype=_2c3mugr67ej6j7._udp. domain=local.
~ DNSServiceQueryRecord callback: Ref=17bd40, Flags=2, IFIndex=2 (name=[en0]), ErrorType=0 fullname=00eGs1R1A\.\.Only\032by\032Audi._2c3mugr67ej6j7._udp.local. rrtype=16 rrclass=1 rdlen=18 ttl=4500
** peer 1527211048: oldbusy=0, newbusy=0
~ DNSServiceBrowse callback: Ref=187f70, Flags=2, IFIndex=-3 (name=[]), ErrorType=0 name=00eGs1R1A..Only by Audi regtype=_2c3mugr67ej6j7._udp. domain=local.
GKPeer[186960] 1527211048 service count old=1 new=2
~ DNSServiceQueryRecord callback: Ref=17bd40, Flags=2, IFIndex=-3 (name=[]), ErrorType=0 fullname=00egs1r1a\.\.only\032by\032audi._2c3mugr67ej6j7._udp.local. rrtype=16 rrclass=1 rdlen=18 ttl=7200
** peer 1527211048: oldbusy=0, newbusy=0
~ DNSServiceBrowse callback: Ref=187f70, Flags=2, IFIndex=-3 (name=[]), ErrorType=0 name=00TF5kc1A..Only by Audi regtype=_2c3mugr67ej6j7._udp. domain=local.
~ DNSServiceQueryRecord callback: Ref=188320, Flags=2, IFIndex=-3 (name=[]), ErrorType=0 fullname=00tf5kc1a\.\.only\032by\032audi._2c3mugr67ej6j7._udp.local. rrtype=16 rrclass=1 rdlen=18 ttl=7200
** peer 1723356125: oldbusy=0, newbusy=0
~ DNSServiceQueryRecord callback: Ref=188320, Flags=2, IFIndex=2 (name=[en0]), ErrorType=0 fullname=00TF5kc1A\.\.Only\032by\032Audi._2c3mugr67ej6j7._udp.local. rrtype=16 rrclass=1 rdlen=18 ttl=4500
** peer 1723356125: oldbusy=0, newbusy=0

What I'm missing here ?

I'm sure that both devices have bluetooth enabled and connected into the same WiFi.

thanks,

r.

A: 

I had similar problems, but from the description above I think you are making some errors:

GKSession only implements BT; if you use the picker, then you can provide separate methods for dealing with WiFi connections.

The "didReceiveConnectionRequestFromPeer" method should call the "acceptConnectionFromPeer" method on the session object -- you do not implement the "acceptConnectionFromPeer" on your delegate.

For debugging, you should log state changes in the delegate method "session:peer:didChangeState:" (see http://developer.apple.com/iPhone/library/documentation/GameKit/Reference/GKSessionDelegate_Protocol/Reference/Reference.html ). When a peer is "Available", you can call "connectToPeer:"; when "Connected", you can use "sendData:toPeers:".

For IO after you have established a connection, you want to have called the "setDataReceiveHandler:withContext:" method on the session.

Earlier I had some typos in my code but it is now working.

Good luck.

BJ
Hello,I have those delegates methods implemented, but I didn't write them to the code.Also my session:peer:didChangeState never get calls when using GKSession, but it gets called when I use the picker.Until I found more info about what can be wrong or why it's not working, I'm using the GKPicker ...thanks, at least I know I'm not the only one ...:-)regards,r.
mongeta