2

I currently have a method that sends data through Bonjour. The problem is that my data is limited to 1000 kB. I know that if I want to send larger data I need to break it in to packets.

But this raises a question of how do I prevent packets from being lost, and ensure all packets are received by the receiver.

I am not good with network and would like to ask you to help me change this simple method to enable larger data transfer.

- (BOOL)sendData:(NSData *)data error:(NSError **)error {
    BOOL successful = NO;
    if(self.outputStreamHasSpace) {

        NSInteger len = [self.outputStream write:[data bytes] maxLength:[data length]];
        if(-1 == len) {
            // error occured
            *error = [[NSError alloc] 
                      initWithDomain:ServerErrorDomain
                      code:kServerNoSpaceOnOutputStream
                      userInfo:[[self.outputStream streamError] userInfo]];
        } else if(0 == len) {
            // stream has reached capacity
            *error = [[NSError alloc] 
                      initWithDomain:ServerErrorDomain
                      code:kServerOutputStreamReachedCapacity
                      userInfo:[[self.outputStream streamError] userInfo]];
        } else {
            successful = YES;
        }
    } else {
        *error = [[NSError alloc] initWithDomain:ServerErrorDomain
                                            code:kServerNoSpaceOnOutputStream
                                        userInfo:nil];
    }

 return successful;
}

Thank you.

Cyprian
  • 9,423
  • 4
  • 39
  • 73
  • @Joe Blow you are right although GAMEKIT hides to much behind the scenes. I already solved the problem with the data larger then my buffer. – Cyprian Apr 28 '11 at 10:43

1 Answers1

0

You're not sending them over 'Bonjour', you're sending UDP packets to a multicast address. On most networks the maximum frame size is 1500 bytes. Realistically, allowing for headers, vlan tags, etc, you have about 1.3 - 1.4k of data per frame to fill. As the data's going over UDP, controlling the correct reception and ordering of packets is up to you- it's one of the drawbacks of not using TCP ;)

Chris Mowforth
  • 6,689
  • 2
  • 26
  • 36