Travis
Travis

Reputation: 137

Java Downloading Flood Prevention

currently I have a java downloader that downloads a .zip file and uncompresses it, however the host has an 8mb download speed limit. So due to bandwidth issues if more then 10 people are concurrently downloading the file (which is about 30MB) it causes the download speed to go down drastically, causing it to go from taking 2 minutes to 10 hours

Anyways, here's the downloading code

BufferedInputStream in = new BufferedInputStream(new java.net.URL(
"http://example.com/exampleJar.jar").openStream());
FileOutputStream fos = new FileOutputStream("exampleJar.jar");
BufferedOutputStream bout = new BufferedOutputStream(fos);

I'm thinking, perhaps a method to check how many people are downloading it, and if X amount of people are currently downloading, switch to a different link which could be found in an array of links.

Upvotes: 1

Views: 396

Answers (1)

Dapeng
Dapeng

Reputation: 1716

this should be done at the server side rather than client side

depending on what kind of server u use, find a way to count currently running requests

if more than your preset value

send http 302 http temporarily moved, and give another download URL

say

http://download2.example.com/exampleJar.jar

Upvotes: 2

Related Questions