开发者

Sending large data over bonjour

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:[[se开发者_Python百科lf.outputStream streamError] userInfo]];
        } else {
            successful = YES;
        }
    } else {
        *error = [[NSError alloc] initWithDomain:ServerErrorDomain
                                            code:kServerNoSpaceOnOutputStream
                                        userInfo:nil];
    }

 return successful;
}

Thank you.


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 ;)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜