I am working on an assignment for my Networks class and we have to use sockets to download an image from the web. The idea is to open 5 separate sockets, run them concurrently in separate threads and have them each download a part of the file then stitch them back together after getting the different parts. What I am confused about is how would the second thread know to start the stream at the point the first one ended? Like I have:
InputStream is = new BufferedInputStream(socket.getInputStream());
DataOutputStream dout = new DataOutputStream(socket.getOutputStream());
String request = "GET " + path + " HTTP/1.0\n\r\n\r";
dout.write(request.getBytes());
Then the loop that reads the stream:
while ((bytes = is.read(buffer)) != -1)
But if this is happening every time a run a new thread and create a new socket/TCP connection, how can set the stream to start at the point the last stream stopped? To clarify a bit more, the first thread should create a file called image.jpg.part1 then the second image.jpg.part2 and so on. Then we combine the parts into the original image.
Thanks!