Android Wifi Direct - Distance based P2P file sharing

526 views Asked by At

I have an academic project, where I have to make an android app to implement distance based wifi direct P2P file sharing. Three devices are involved in this - one is the file requesting device (say A) and two devices have the file (say B & C). Device A should download from a device B or C whichever is nearest to it (lets say B is nearer). Whenever B moves away from A, so that its distance from A is more than d(A,C), A should connect to C and resume the download where it got disconnected from B. Till now I am able to implement distance based file sharing part (by setting some distance thresholds). But I have no idea how to implement the download resuming thing.

1

There are 1 answers

0
JstnPwll On

See this answer: Implement pause/resume in file downloading

It is intended for download using HTTP, but you can use the same principles and modify it to fit your use case.

Basically, you need to keep track of how many bytes you've read so far. When you connect to a new download source, pause the download and send your current byte count to the new device. That device can then respond, starting from the appropriate point, and stream the remainder of the bytes.

You'll probably want to use RandomAccessFile to allow seeking between byte positions during your operations.