Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

HttpClient times out when changing from 3G to WiFi

Tags:

android

I perform some large downloads. I start a download being connected to 3G, all is fine. Then, I switch to WiFi connection, but the request returns a timeout exception. I have used HttpClient library. I have implemented a retry mechanism, so, when the request returns an exception, it sleeps for 0.5 seconds and tries to execute again and again. I would expect that, after connecting to a WiFi, the Http request could execute. But it seems that the Http execute method returns a null response, all the time after that. Very strange, if I commute again to 3G, the execute method returns again a good response. Can anyone help me please :) ?

like image 255
Muresan Catalin Avatar asked Mar 15 '12 15:03

Muresan Catalin


1 Answers

First, it seems that it may be more convenient to use DownloadManager for large files - it handles retry and everything.

As for HttpClient - it's known to have some issues, but i'm not sure if you bumped into one of them or just overlooked something. It's been deprecated as of Gingerbread, you may want to try HttpUrlConnection instead, it's said to have less problems than HttpClient.

Also, when switching between WIFI and cell connections, HttpClient may need to be reinitialized completely, there's http range header to tell server which byte you want to continue downloading from. But again, I suggest you give DownloadManager a try, it may save you a lot of time.

like image 52
Ivan Bartsov Avatar answered Oct 15 '22 19:10

Ivan Bartsov