views:

1023

answers:

3

Hello!

Since some time I've been playing with GameKit, but now I'm facing relly bad difficulties.

I'm going to send through Bluetooth bigger files - 1-2MB. I've already prepared a packets (about 8kB each).

My app works as described on followin scheme:

iPhone - sending header: file divided into 25 parts
iPod - received header: OK I got it waiting for 25 parts
iPhone - sending part #1
iPod - received part #1 send next
iPhone - sending part #2
iPod - received part #2 send next
...
iPhone - sending part #24
iPod - received part #24 send next
iPhone - sending part #25
iPod receiving part #25 processing file

I send both file parts and messages (confirmation od delivery) using:

[mSession sendData:data toPeers:mPeers withDataMode:GKSendDataReliable error:nil];

and receiving data:

- (void)receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context

I would like to know how do you deal with some problems that may occure during bluetooth transmission. Browsing the documentations GKSessionDelegate doesn't give me any info if the data was delivered or not.

In 90% cases the transfer works fine, but sometimes it suddenly stops and doesn't continue without reconnection/restart the app.

I triend to invent a easy solution to set the data again if I won't get the response within 1sec:

-(void)sendAgain {
    [self sendData:bufor];
}
-(void)sendData:(NSData *)data {
    bufor = [data retain];

    timeoutTimer = [NSTimer scheduledTimerWithTimeInterval:1.0 target:self selector:@selector(sendAgain) userInfo:nil repeats:NO];

    [mSession sendData:data toPeers:mPeers withDataMode:GKSendDataReliable error:nil];
}

timeOutTimer is invalidated if sender received confirmation of succesful delivery of file part. But in fact when I implement this solution there are even more problems with this.

Devices are next to each other on the desk.

So guys, please tell me, how do you deal with problems of "undelivered" data between devices? It's just a tool, but how it could be annoying while developing games?

BTW Sending short chats messages never caused any problem and I'm using the same methods.

In fact the connection get lost very rarely, just the data likes to be lost in the air. I'm already dividing the parts so the size of the data is about 8kb, what really makes the transfer of images really really slow.

A: 

How did you come up with the 8kb packet size? According this article by Apple they recommend to keep the packets within 1000 bytes. Refer to the paragraph under "exchanging data".

http://developer.apple.com/iphone/library/documentation/NetworkingInternet/Conceptual/GameKit%5FGuide/GameKitConcepts/GameKitConcepts.html#//apple%5Fref/doc/uid/TP40008304-CH100-SW1

it
+1  A: 

The GameKit framework isn't very reliable at this point, even for simple exchange of data for games I work on. I wouldn't use it to transmit large data, you're just asking for headaches.

refulgentis
A: 

I agree with both "it" and "refulgentis". Doing this over GK is asking for unreliable execution. You are better off setting this up over Bonjour and wiFi or having each user download the content from some central offline source. If your design requires that the big files move from one device to another, you might want to upload them on one side and download them on the other, rather than trying to device-to-device transfer files that large.

fogelbaby