Tutorial :how to checksum a file transfer with java servlet and HttpURLConnection



Question:

I'm trying to guarantee a file transfer. I guess that I could do it with some kind of checksum.

Also, because of some inner issues, I need to do it with streaming.

I thought of calculating a digest before and after the transfer but the error would appear only at the end of the transfer. I'm searching for some kind of chunked checksum with re-send if any error.

Any suggestion?

Thanks!


Solution:1

I think you're going to have to do something at a higher level in the stack - HTTP doesn't have the capability to retransmit part of the response mid-stream. Once the client makes an HTTP request, it must receive the entire HTTP response before it can make another request. HTTP chunking is mostly to facilitate keep-alive connections without having to calculate the content-length of the response ahead of time.

If we're talking about a custom client and server here (which I assume we are since this question wouldn't make sense if you're talking about a browser) then maybe one way to do it would be for the server to chop the file into pieces and have the client request each piece of the file one at a time using a keep-alive connection. If you send back a checksum for each piece in the response (i.e. in an ETag header), you could calculate the checksum on the client to ensure you received the correct bytes. If the checksum doesn't match, just have the client request that chunk over again.


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »