10

I am downloading a large size zip file from server. I am getting following

06-11 21:45:18.789: I/System.out(8993): java.net.SocketException: recvfrom failed: ETIMEDOUT (Connection timed out)

My application does not stop, but my downloading stops. This happens on hdpi android mobile specifically saying low processor devices. The downloading works fine on S3 and tablets. I am using simple FileOutputStream method to download the file.

5 Answers5

4

I guess, you should acquire a WakeLock in order to finish your download, and then release it. Especially, if you're downloading a large file via a Wi-Fi connection, it is typical to acquire a WifiLock in order to keep radio awake.

On the other hand, you might (if you do not already) as well try DownloadManager. As this official article on wakelocks states,

"If your app is performing long-running HTTP downloads, consider using DownloadManager."

Drew
  • 3,307
  • 22
  • 33
3

If you are using HttpConnection then increase Timeout

HttpURLConnection con = (HttpURLConnection) url.openConnection();

con.setReadTimeout(10000 );

OR

HttpConnectionParams.setSoTimeout(httpParameters, 10000); //

hharry
  • 422
  • 1
  • 9
  • 21
  • Nop @hharry i am using **BufferedInputStream input = new BufferedInputStream(url.openStream(),8192);** –  Jun 12 '13 at 12:26
  • According to this SO [link](http://stackoverflow.com/questions/2638283/can-i-set-a-timeout-for-a-inputstreams-read-function) you can set timeout on sockets. `Socket#setSoTimeout(int)`. – Lukasz 'Severiaan' Grela Sep 03 '13 at 12:55
1

I'm not pretty sure this might be the issue but it's a possibility. You say this happens on low processor devices, it might happen that the remote servers upstream bitrate is that big that the client's downstream bitrate can't handle it, and as this happens with large files, after a certain amount of time the receiver device can't handle the bitrate, the Socket collapses and you get that timeout.

My suggestion is trying to implement a bandwith rate limiter. This way you can test whether the slow devices respond better to those long downloads, though they will be slower.

Community
  • 1
  • 1
nKn
  • 13,691
  • 9
  • 45
  • 62
0

Below links might be useful to you

Android download large files

Android - Large file downloads stop - using async/progressdialog

try loopj lib to download file asynchronously http://loopj.com/android-async-http/ i am not sure about loopj lib to download large file but you can do it via trial and error.

Community
  • 1
  • 1
Rohan Pawar
  • 1,875
  • 22
  • 40
0

To work with a HTTP server I strongly suggest Loopj library to you, it's a reliable, simple and easy to use library. as documentation said you can download a file simply like this:

AsyncHttpClient client = new AsyncHttpClient();
String[] allowedContentTypes = new String[] { "image/png", "image/jpeg" };
client.get("http://example.com/file.png", new BinaryHttpResponseHandler(allowedContentTypes) {
    @Override
    public void onSuccess(byte[] fileData) {
        // Do something with the file
    }
});
Sadegh
  • 2,669
  • 1
  • 23
  • 26