Determine internet connection speed of the device.

Hi again,

Some day i was staying in metro and testing the app i’ve been working on.  Something went wrong. Issue was that images were not loaded as device was connected to the internet via GPRS.

App should load smaller images.Luckily server supports multi-res image output.

I defined 4 important for us states
11-04-2013 17-58-15

There are 3 ways of getting conenction speed on device. And only 1 of them works properly.
1. HttpWebRequest and WebRequestExtensions.GetCurrentNetworkInterface (not reliable)
2. DeviceNetworkInformation.ResolveHostNameAsync (breaks tombstoning)
3. Socket and SocketExtensions.GetCurrentNetworkInterface

The third option works like a charm.

Here you can see how socket to Googles Public DNS server is opened and NetworkInterfaceInfo is extracted. Speed assumptions are based on NetworkInterfaceInfo.Bandwidth
11-04-2013 18-17-20

Basing on ConnectionSpeed and on DeviceSpeed
11-04-2013 18-04-02

we decide what image to load via nice matrix
11-04-2013 18-05-54

All the code is in the Zip file on the dropbox.
https://www.dropbox.com/s/5ib47l93j6nwg1v/ConnectionSpeed.zip

Important:  Don’t forget to invoke ConnectionSpeedManager.CheckConnection() in Apps OnLaunch and OnActivate methods

Advertisements