0

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.

Raghu
  • 1,324
  • 7
  • 24
  • 47

3 Answers3

0

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}
}
Saurabh Jhunjhunwala
  • 2,832
  • 3
  • 29
  • 57
0

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.

Christophe
  • 2,131
  • 2
  • 21
  • 35
0

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!

Community
  • 1
  • 1