I have client/server architecture , The problem I am facing is like this. Here Client
is java program , connect using HttpURLConnection
and server is a Servlet. Once Client make a request Servlet sends a file through Stream . and client will download it from Stream . This process is working fine . The problem is suppose if file was not successfully download in client , client has to send message to server so that it will send the file again (I want this to be happen without making new connection). How to achieve this in a single request. can anyone help me in this.

- 1,324
- 7
- 24
- 47
3 Answers
why dont you write an infinite while loop, which would keep connecting to the server until you get a positive response. I mean
// create your connection instance
while(true){
try{
// connect to server and get the file
break;
} catch (Exception ){ // do something}
}

- 2,832
- 3
- 29
- 57
-
yes my application is continuously connect to server every 10 sec. – Raghu Apr 29 '15 at 13:31
-
thanks you , its time to logout here . can I contact u tommarow? – Raghu Apr 29 '15 at 13:34
In order to know that the client has a problem you have to send a new request. You just can't do what you want.

- 2,131
- 2
- 21
- 35
Your question is similar to this one: How to Reuse HttpUrlConnection?
Which in return got answered already in: Persistent HttpURLConnection in Java
The answer for your question remains the same: You set the http.keepAlive
and http.maxConnections
properties, and let Java handle the HTTP persistence transparently.
Now, I have reason to believe that both answers won't help you, because what you are normally interested in for file downloads, is not restarting the entire download, but continueing a previous download.
That question was also already answered in: Java: resume Download in URLConnection
Hope this helps!

- 1
- 1

- 53
- 3