SocketException同时下载大尺寸的zip文件

时间:2021-12-19 09:56:28

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

我正在从服务器下载一个大尺寸的zip文件。我得到后

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.

我的应用程序没有停止,但是我的下载停止了。这发生在hdpi android手机上,专门说低处理器设备。下载在S3和平板电脑上运行良好。我正在使用简单的FileOutputStream方法来下载文件。

5 个解决方案

#1


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.

我猜,你应该买一个WakeLock来完成你的下载,然后发布它。特别是,如果你正在通过Wi-Fi连接下载一个大文件,通常需要获取一个WifiLock来保持广播清醒。

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

另一方面,您也可以尝试下载管理器(如果还没有的话)。正如这篇关于wakelocks的官方文章所言,

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

“如果您的应用程序正在执行长时间的HTTP下载,请考虑使用DownloadManager。”

#2


3  

If you are using HttpConnection then increase Timeout

如果您正在使用HttpConnection,那么增加超时

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

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

con.setReadTimeout(10000 );

con.setReadTimeout(10000);

OR

HttpConnectionParams.setSoTimeout(httpParameters, 10000); //

HttpConnectionParams。setSoTimeout(httpParameters,10000);/ /

#3


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.

我的建议是尝试实现带速率限制器的带宽。通过这种方式,您可以测试慢速设备对长下载的响应是否更好,尽管它们会更慢。

#4


1  

Below links might be useful to you

下面的链接可能对您有用

Android download large files

安卓系统下载大文件

Android - Large file downloads stop - using async/progressdialog

大型文件下载停止-使用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.

尝试loopj lib异步下载文件http://loopj.com/android- asyn-http/我不确定loopj lib是否可以下载大型文件,但是您可以通过尝试和错误来完成。

#5


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:

要使用HTTP服务器,我强烈建议您使用Loopj库,它是一个可靠、简单且易于使用的库。正如文件所说,你可以像这样简单地下载一个文件:

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
    }
});

#1


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.

我猜,你应该买一个WakeLock来完成你的下载,然后发布它。特别是,如果你正在通过Wi-Fi连接下载一个大文件,通常需要获取一个WifiLock来保持广播清醒。

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

另一方面,您也可以尝试下载管理器(如果还没有的话)。正如这篇关于wakelocks的官方文章所言,

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

“如果您的应用程序正在执行长时间的HTTP下载,请考虑使用DownloadManager。”

#2


3  

If you are using HttpConnection then increase Timeout

如果您正在使用HttpConnection,那么增加超时

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

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

con.setReadTimeout(10000 );

con.setReadTimeout(10000);

OR

HttpConnectionParams.setSoTimeout(httpParameters, 10000); //

HttpConnectionParams。setSoTimeout(httpParameters,10000);/ /

#3


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.

我的建议是尝试实现带速率限制器的带宽。通过这种方式,您可以测试慢速设备对长下载的响应是否更好,尽管它们会更慢。

#4


1  

Below links might be useful to you

下面的链接可能对您有用

Android download large files

安卓系统下载大文件

Android - Large file downloads stop - using async/progressdialog

大型文件下载停止-使用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.

尝试loopj lib异步下载文件http://loopj.com/android- asyn-http/我不确定loopj lib是否可以下载大型文件,但是您可以通过尝试和错误来完成。

#5


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:

要使用HTTP服务器,我强烈建议您使用Loopj库,它是一个可靠、简单且易于使用的库。正如文件所说,你可以像这样简单地下载一个文件:

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
    }
});