- Joined
- Jun 27, 2006
- Messages
- 23,048
- Thread Author
- #1
Today's project comes from Charles Torre. While the component's source isn't currently available, when I saw this post on the Visual Studio Gallery was from him, what looks like his first, well had to share it!
As if I need to tell you all this, but we live in a connected world, more so every day, and so it's even more important that our app's know and respond appropriately. Connected or not is one thing, "well" connected is another. Charles provides an API that will help you and your app's determine if there's a fast connection or not...
Link Removed
This is a convenient Windows multi-language API for making Internet connection state decisions in real time, using the speed result to decide if/when to run your network-intensive code.
...
API
InetSpeedWinRTWindows80
InetSpeedWinRTWindows81
class InternetConnectionState
object that contains the static members you use to determine Internet connection state (connection status and speed/latency/delay)
Properties
static bool Connected
Returns true if the current Internet connection for the device is active, else false.
Methods
static IAsyncOperation<ConnectionSpeed> GetInternetConnectionSpeed();
Asynchronous method that will return a ConnectionSpeed (see below).
static IAsyncOperation<ConnectionSpeed> GetInternetConnectionSpeedWithHostName(HostName hostName);
Asynchronous method that will perform the speed/latency test on a supplied host target and returns a ConnectionSpeed. This is very useful to ensure the Internet resource you’re trying to reach is available at the speed level you require (generally, these would be High and Average…).
enum class ConnectionSpeed
Speed test results are returned as an enum value (For JavaScript consumers, you’ll need to build your own object mapping. See the JavaScript example).
High: Device is currently attached to a high-speed, low-latency Internet connection.
Average: Device is currently attached to an average speed/latency Internet connection (LTE, 3G, etc…).
Low: Device is currently attached to a low-speed, high-latency Internet connection.
Unknown: The current Internet connection speed can't be determined. Proceed with caution. This could mean that there is very high network latency, a problem with an upstream service, etc...
Example (C# consumer):
This example tests for a highspeed network based on a provided HostName (this is the best way to use this API given you really want to know the status of the Internet connection as it pertains to where you need to put/grab data over the network in real time...). Note you should always test for Unknown and then react accordingly (don't proceed with network work. Unknown means you are connected to the Internet, but you can't do network work with acceptable latency.)
High and Average are the two results you should test for before doing network work that involves either downloading or uploading data.
using InetSpeedWinRTWindows81;
...
if (InternetConnectionState.Connected)
{
var speed =
await InternetConnectionState.GetInternetConnectionSpeedWithHostName(new HostName("targethost.com"));
if (speed == ConnectionSpeed.High)
{
\\Current network speed is High, low latency
}
else if (speed == ConnectionSpeed.Average)
{
\\Current network speed is Average, average latency
}
else if (speed == ConnectionSpeed.Low)
{
\\Current network speed is Low, high latency
}
else
{
\\Current Network Speed is Unknown - use at your own risk...
}
}
else
{
ResultsBox.Text = "Not Connected to the Internet!";
}
}
...
Known issue with Windows Phone radio when the device resumes from standby
When Windows Phone devices resume from standby, the time it takes for the cellular radio to fully “awaken” can lead to inaccurate results from InetSpeedWinRT (the ConnectionSpeed result in this case is typically Low or Unknown – and this has been verified in extensive testing to be inaccurate as a subsequent call will return the actual state, typically higher…)… This is not a bug in InetSpeedWinRT. This is an issue faced by any app that makes network calls upon device then app resumption.
One simple workaround is to touch the network interface from both Application_Launching and Application_Activated event handlers (typically in your App class implementation file). By doing this ...
Link Removed
Link Removed
Link Removed
Page Thumbnail courtesy of jonel hanopol, under creative commons
Link Removed
Continue reading...
As if I need to tell you all this, but we live in a connected world, more so every day, and so it's even more important that our app's know and respond appropriately. Connected or not is one thing, "well" connected is another. Charles provides an API that will help you and your app's determine if there's a fast connection or not...
Link Removed
This is a convenient Windows multi-language API for making Internet connection state decisions in real time, using the speed result to decide if/when to run your network-intensive code.
...
API
InetSpeedWinRTWindows80
InetSpeedWinRTWindows81
class InternetConnectionState
object that contains the static members you use to determine Internet connection state (connection status and speed/latency/delay)
Properties
static bool Connected
Returns true if the current Internet connection for the device is active, else false.
Methods
static IAsyncOperation<ConnectionSpeed> GetInternetConnectionSpeed();
Asynchronous method that will return a ConnectionSpeed (see below).
static IAsyncOperation<ConnectionSpeed> GetInternetConnectionSpeedWithHostName(HostName hostName);
Asynchronous method that will perform the speed/latency test on a supplied host target and returns a ConnectionSpeed. This is very useful to ensure the Internet resource you’re trying to reach is available at the speed level you require (generally, these would be High and Average…).
enum class ConnectionSpeed
Speed test results are returned as an enum value (For JavaScript consumers, you’ll need to build your own object mapping. See the JavaScript example).
High: Device is currently attached to a high-speed, low-latency Internet connection.
Average: Device is currently attached to an average speed/latency Internet connection (LTE, 3G, etc…).
Low: Device is currently attached to a low-speed, high-latency Internet connection.
Unknown: The current Internet connection speed can't be determined. Proceed with caution. This could mean that there is very high network latency, a problem with an upstream service, etc...
Example (C# consumer):
This example tests for a highspeed network based on a provided HostName (this is the best way to use this API given you really want to know the status of the Internet connection as it pertains to where you need to put/grab data over the network in real time...). Note you should always test for Unknown and then react accordingly (don't proceed with network work. Unknown means you are connected to the Internet, but you can't do network work with acceptable latency.)
High and Average are the two results you should test for before doing network work that involves either downloading or uploading data.
using InetSpeedWinRTWindows81;
...
if (InternetConnectionState.Connected)
{
var speed =
await InternetConnectionState.GetInternetConnectionSpeedWithHostName(new HostName("targethost.com"));
if (speed == ConnectionSpeed.High)
{
\\Current network speed is High, low latency
}
else if (speed == ConnectionSpeed.Average)
{
\\Current network speed is Average, average latency
}
else if (speed == ConnectionSpeed.Low)
{
\\Current network speed is Low, high latency
}
else
{
\\Current Network Speed is Unknown - use at your own risk...
}
}
else
{
ResultsBox.Text = "Not Connected to the Internet!";
}
}
...
Known issue with Windows Phone radio when the device resumes from standby
When Windows Phone devices resume from standby, the time it takes for the cellular radio to fully “awaken” can lead to inaccurate results from InetSpeedWinRT (the ConnectionSpeed result in this case is typically Low or Unknown – and this has been verified in extensive testing to be inaccurate as a subsequent call will return the actual state, typically higher…)… This is not a bug in InetSpeedWinRT. This is an issue faced by any app that makes network calls upon device then app resumption.
One simple workaround is to touch the network interface from both Application_Launching and Application_Activated event handlers (typically in your App class implementation file). By doing this ...
- Link Removed
- Link Removed
Link Removed
Link Removed
Link Removed
Page Thumbnail courtesy of jonel hanopol, under creative commons
Link Removed
Continue reading...