java - Concurrent and In Order Downloading chunks from 2 servers - Android -


i working on android app purpose download chunks(parts of video file) 2 servers, append them in order(into main video file) after each 1 downloaded , play video file while downloading continues..

this works when downloading done serial using 2 different threads(one each server) perform downloading. want know how possible achieve above concurrent downloading, instead of serial.

that download chunks servers @ same time , in order. example, for same period of time download chunk0, chunk1 & chunk2 server1 (which let's 3 times faster server2) , chunk3 server2, totally use available bandwidth of 2 servers @ period of time. , process repeats until chunks downloaded.

by using threads , join, downloading serial, said above. in order make concurrent, tried remove join each thread, doesn't download chunks in order , download 1 server, not both. asynctask not solution, doesn't download chunks in order.

so, there way achieve concurrent , in order downloading of chunks described above? has done project, know answer sure?

you may use popular technique among download accelerators.

in general, idea requesting chunks each server using range http header. (the server responds accept-ranges header when capable of processing range header accordingly). (this blog has explanation that).

every thread/runnable/callable has know chunk responsibility ( first byte position + length ?) because each 1 have write own part in file.

then there decision made, can:

  1. write file using instance of randomaccessfile in each thread, positioning file pointer in first byte position of chunk (with seek method), or..

  2. be sure have unique worker thread (see executors , submit) in charge of writing bytes told each thread. in moment of writing, use seek move file pointer correct position, there no errors of overlapping.

note: if want able start playback when have first chunk, may executing code after first chunk thread download+write has finished.


Comments

Popular posts from this blog

jquery - How can I dynamically add a browser tab? -

node.js - Getting the socket id,user id pair of a logged in user(s) -

keyboard - C++ GetAsyncKeyState alternative -