udark / underdark-cocoa

Bluetooth peer-to-peer mesh networking for iOS
http://underdark.io
Other
123 stars 24 forks source link

how to transfer large file #1

Open zhuozhuo opened 8 years ago

zhuozhuo commented 8 years ago

Hi, I want transfer large file with iPhone and android。To send data to the android on the iPhone side,on the iPhone side memory has been increased to collapse。Do you have any good Suggestions? Thanks!

virl commented 8 years ago

@zhuozhuo Hi! Please post here the code that you use for sending that file.

Also please note that sendFrame()/broadcastFrame() methods send frames of arbitrary size atomically — so usually you can send image in one frame without splitting it into multiple frames.

zhuozhuo commented 8 years ago
 NSInteger bufferLenth = 1024;
    NSString *path = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"img"];
    NSData *imgData = [NSData dataWithContentsOfFile:path];
    NSLog(@"imgDataLength:%ld",imgData.length);
    NSInteger sendDataIndex = 0;
    while (sendDataIndex<imgData.length) {
        NSInteger amountToSend = imgData.length - sendDataIndex;
        if (amountToSend > bufferLenth) {
            amountToSend = bufferLenth;
        }
        NSData *sendData = [NSData dataWithBytes:(imgData.bytes + sendDataIndex) length:amountToSend];

        [darkNode broadcastFrame:sendData];
      sendDataIndex += amountToSend;
    }
virl commented 8 years ago

@zhuozhuo I don't understand what does the while loop do in your code. Why are you looping through image bytes?

Also please re-read my previous message about frame.

Basically all you want to do is following without any loops:

 NSString *path = [[NSBundle mainBundle]pathForResource:@"test" ofType:@"img"];
 NSData *imgData = [NSData dataWithContentsOfFile:path];

[darkNode broadcastFrame: imgData];

Also how big is your image file?

zhuozhuo commented 8 years ago

500M

virl commented 8 years ago

@zhuozhuo iOS and Android devices don't have enough RAM to have such file in memory. So you can't even just call [NSData dataWithContentsOfFile:path];

You must load it from disk in chunks and send these chunks over a network one at a time, with confirmation from receiving side before sending next chunk.

zhuozhuo commented 8 years ago

I think so, but I can't see success to receive the callback function interface you provided.

virl commented 8 years ago

@zhuozhuo Such receive confirmation callback is planned for future version of the library.

For now, you can emulate it by sending your own special frame from the receiver back to the sender with (for example) index of received chunk. And when sender receives such confirmation, it can load the next chunk of the image file from the disk and send it over network.

zhuozhuo commented 8 years ago

Thank you, I see, looking forward to the next version.

virl commented 8 years ago

@zhuozhuo I recommend to try to emulate it for now — it must be quite simple.

I will leave this Issue open and post to you when this functionality will be implemented in the library.

zhuozhuo commented 8 years ago

Thanks again. If I have any questions to ask you again.

virl commented 8 years ago

By the way, why you need to transfer so large image file? What is it for?

zhuozhuo commented 8 years ago

The system upgrade to the android intelligent watch send documents.Img file generated by the terminal.

virl commented 8 years ago

What for?

On 19 Jan 2016, at 04:51, Mr.jiang notifications@github.com wrote:

The system upgrade to the android intelligent watch send documents.Img file generated by the terminal.

— Reply to this email directly or view it on GitHub.

zhuozhuo commented 8 years ago

The img file just a test. In order to send android smart watch system upgrade file.

zhuozhuo commented 8 years ago

Hi,In the wifi environment, how to speed up the transmission speed!

virl commented 8 years ago

@zhuozhuo Library uses standard sockets for Wi-Fi transfer, so it must work with full speed of your Wi-Fi. Maybe there is room for some optimizations in the code — I'll look at them later.

zhuozhuo commented 8 years ago

ok,thanks!