0

On the first app start I download ~50 mb of files and then unzip them..
I have users from around the world and I have 3 different server that I can host the files, so I thought of using them all and check by code which server is the fastest/closest to user and to use that..

How can I achieve that?

Omar
  • 7,835
  • 14
  • 62
  • 108

5 Answers5

1

Why don't you use the Google Play service for adding "expansion files"? See here: http://developer.android.com/guide/google/play/expansion-files.html

I didn't try it personally, but it should definitely help you.

YuviDroid
  • 1,546
  • 11
  • 12
0

Maybe send a simple request to a kind of ping.php script to each server, measure the time taken to read the response and pick the best one. Don't forget to send a first request to a dummy server or to download a web page in order for the phone to activate the network and set it to best performance possible (else your first server might always look slow compared to the next ones).

Vincent Mimoun-Prat
  • 28,208
  • 16
  • 81
  • 124
0

I've never done this before, so this is just a guess, but if you want to find out which is closer:

Get the User's IP Address: How to get IP address of the device from code?

Do a reverse DNS lookup on the IP address, which will give you something like this: c-24-131-5-42.hsd1.va.comcast.net

By looking at the resulting string, you can tell that I live in VA. Using the country/state figure out which is closer to your server and use it.

Community
  • 1
  • 1
Michael
  • 3,334
  • 20
  • 27
0

To do this yourself; you'll need to query a geo ip service with the IP address of the device to get its approximate location; then compare that with which server to best serve the file from. This has its own problems (proxy/vpn tunnels being one of them).

Second is to ping your server. The problem here could be that ping may be blocked by the provider (especially if the device is on not on wifi); even if they are on wifi, ping may be blocked for external addresses and only allowed within the network. In this case; the ping will always fail.

So the reliable way is to use a Content Delivery Network. They will take care of serving the file from the closest possible server automatically. You don't have to modify your application or manage different servers.

Burhan Khalid
  • 169,990
  • 18
  • 245
  • 284
0

You could also try to establish a TCP connection with every server that you have and track the time taken to do that. Then use the one that has the minimum time.

Or have the device pull a file from each server containing the server's known availability.

slybloty
  • 6,346
  • 6
  • 49
  • 70