Android Question Issue downloading files with HttpUtils2 on Mobile Data

dieterp

Active Member
Licensed User
Longtime User
Hi

My app uses HttpUtils2 to download images from a server. The files are not big, and I can have up to 20-30 files download at a time. The app will only download a file once a success message has been received in JobDone that the previous file was successfully downloaded.

When I run this process connected to Wifi the files will download every time without fail. When I use Mobile Data though (Wifi disconnected), at some point one of the files will 'hang' and I'll eventually get the timeout message of 'SocketTimeOutException'. This happens almost every time on Mobile Data. At one point I restarted my device and it worked, but subsequently it has started happening again and even a restart doesn't fix it.

What are my options here? The mobile Data has a 4G connection so speed isn't an issue. The Wifi has a 3G connection, so even when I force my device to use 3G as Mobile Data, I still get the issue.
 

KMatle

Expert
Licensed User
Longtime User
Which phone do you have and which ROM (custom or other like Cyanogen)? What about other downloads (f.e. via browser). Does this work?

I have some apps doing the same. No problem (file size is about 150-200 KB).

As a workarround you can increase the timeout with:

B4X:
Job.Download(...)
Job.GetRequest.Timeout = 60000
 
Upvote 0

dieterp

Active Member
Licensed User
Longtime User
I have a Samsung Galaxy S5, so there shouldn't be any issues with the phone specs. The timeout is set to 40 seconds which should be more than enough time, yet the issue still persists.

I don't download many things from any servers so it's hard to say what happens on other downloads, but I can browse the internet with no problems, and generally there aren't problems when I download the actual app from the same server when I'm doing updates.
 
Upvote 0

KMatle

Expert
Licensed User
Longtime User
S5. Ok. That's not the problem. If the 3G/4G connection is stable and at high speed it must be something else. What exactly do you download? Pictures? And what do you do with it? I'm thinking about out of memory problems...
 
Upvote 0

dieterp

Active Member
Licensed User
Longtime User
I download small images that are about 20kb in size and I save them into to the DirDefaultExternal folder of the device. I doubt it could be memory problems as it works fine on Wifi. It must have something to do with the Mobile Data connection. I'm going to try test on different devices. If my device is the only one experiencing the issue on Mobile Data then maybe something is wrong with my device. Will keep you posted!
 
Upvote 0

dieterp

Active Member
Licensed User
Longtime User
I'll try that Erel. I'll also build something in to check that the file has finished copying into the DirDefaultExternal folder before trying to download the next file. I did also find that in Debug mode, when I stop and step through each download I have no problems, if that sheds any light on the situation?

I have tried it on a friends S3 and it works fine on mobile data, so it may be something to do with my phone then. I'd need to test on more devices though.
 
Upvote 0

Erel

B4X founder
Staff member
Licensed User
Longtime User
I'll also build something in to check that the file has finished copying into the DirDefaultExternal folder before trying to download the next file
No need. If File.Copy didn't raise an error then the file was copied successfully.

I did also find that in Debug mode, when I stop and step through each download I have no problems, if that sheds any light on the situation?
Not sure whether it is related.
 
Upvote 0
Top