HttpClient timeout when switching from 3G to Wi-Fi

I am doing a few big downloads. I start the download associated with 3G, everything is fine. Then I switch to the WiFi connection, but the request returns a timeout exception. I used the HttpClient library. I implemented a retry mechanism, so when the request returns an exception, it sleeps for 0.5 seconds and tries to do it all over and over again. I would expect that after connecting to WiFi, the Http request could fulfill. But it seems that the Http execution method returns a null response, all the time after that. It is very strange if I reconnect to 3G, the execute method will return a good answer again. Can someone help me :) :)

+6
source share
2 answers

Firstly, it seems that it is more convenient to use the DownloadManager for large files - it handles the repetition and that’s it.

As for HttpClient - it has some problems, but I'm not sure if you came across one of them or just missed something. It was deprecated like Gingerbread, you can try HttpUrlConnection instead, it said it has fewer problems than HttpClient.

In addition, when switching between WIFI and HttpClient cellular connections, a full reinitialization, the http range header , may be required to inform the server that you want to continue downloading bytes. But then again, I suggest you try DownloadManager, it can save you a lot of time.

+4
source

This may be a routing problem: when switching between different types of networks, usually the local IP address and, more importantly, the local routing table changes due to the use of a different gateway. This means that packets that went perfectly between the client and the server will not be able to reach any destination after changing the network if they send the same route. Most likely, your client implementation should be fully notified of a change or even a restart so that the routing strategy is reinitialized.

If the documentation of the implementation components that you use does not reveal anything, you could try to track this with a packet sniffer such as wirehark. As a rule, there easily appear packages running into nirvana.

0
source

Source: https://habr.com/ru/post/910815/


All Articles