IPhone SDK: GameKit and large files + lost connection
Ever since I played with GameKit, but now I am facing very difficult difficulties.
I am going to send large files via Bluetooth - 1-2 MB. I have already prepared packages (about 8kB each).
My application works as described in the following diagram:
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 am sending both parts of the file and message (delivery confirmation) using:
[mSession sendData:data toPeers:mPeers withDataMode:GKSendDataReliable error:nil];
and getting data:
- (void)receiveData:(NSData *)data fromPeer:(NSString *)peer inSession: (GKSession *)session context:(void *)context
I would like to know how you deal with some of the problems that can arise during Bluetooth transmission. Looking at the GKSessionDelegate documentation doesn't give me any information if the data was delivered or not.
In 90% of cases, the transfer works fine, but sometimes it suddenly stops and does not continue without reconnecting / restarting the application.
I tried to come up with a simple solution to set the data again if I don't get a 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 invalid if the sender has received confirmation of successful delivery of the file part. But actually, when I implement this solution, there are even more problems with this.
The devices are next to each other on the table.
How do you deal with "unresolved" data problems between devices? It's just a tool, but how can that be annoying when developing games?
By the way, sending short chat messages has never caused any problems and I use the same methods.
In fact, the connection is very rarely lost, only data likes to be lost in the air. I already split the parts, so the data size is about 8KB, which really makes the image transfer really really slow.
I agree with "it" and "refulgentis". Doing this on GK requires unreliable execution. You better set this up for Bonjour and wiFi, or each user downloads content from some central offline source. If your design requires large files to move from one device to another, you can download them from one side and upload them to the other, instead of trying to transfer files from device to device large.
source to share