InetSpeedUWP 1.0.0
dotnet add package InetSpeedUWP --version 1.0.0
NuGet\Install-Package InetSpeedUWP -Version 1.0.0
<PackageReference Include="InetSpeedUWP" Version="1.0.0" />
paket add InetSpeedUWP --version 1.0.0
#r "nuget: InetSpeedUWP, 1.0.0"
// Install InetSpeedUWP as a Cake Addin #addin nuget:?package=InetSpeedUWP&version=1.0.0 // Install InetSpeedUWP as a Cake Tool #tool nuget:?package=InetSpeedUWP&version=1.0.0
This is a convenient Windows 10 (10240) 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. The same code works across all Windows 10 devices as this is implemented as a Universal Windows Runtime component.
This API does not need to eat a bunch of network bandwidth to do it's job.
This API fills a small gap in the Windows platform networking APIs by providing developers with a very easy to use, simple abstraction to measure current Internet connection speed, which most apps today are not doing. When apps make connectivity state assumptions based only on the existence of an active Internet connection, a potentially poor experience may result for your customers.
This API will benefit the people using your app, who should always be shielded from network latency under all circumstances. Developers will also benefit as you can be confident that:
a) This easy-to-use API will return a result very quickly, as any API call should
b) This API is accurate and reliable across Windows 10 devices.
Product | Versions Compatible and additional computed target framework versions. |
---|---|
.NET Framework | net is compatible. |
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
Version | Downloads | Last updated |
---|---|---|
1.0.0 | 3,012 | 7/27/2015 |
Internet Connection Speed API for Windows 10 UWP, Version 1.0
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. The same code works across all Windows 10 devices as this is implemented as a Universal Windows Runtime component.
API
namespace InetSpeedUWP
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.
static double RawSpeed
Computed speed, in seconds
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 cannot be determined. Proceed carefully...
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:
C#
using InetSpeedUWP;
...
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!";
}
}
Example (JavaScript consumer):
The JavaScript WinRT projection doesn't support C++ enum class named values. Instead, the enum integer values are passed along...
The following makes the code easier to read -> apply named values (JS objects) to numbers (the speed result integer) received from the native API...
JavaScript
var ConnectionSpeed = { High: 0, Average: 1, Low: 2, Unknown: 3 };
function getConnectionSpeed() {
if (InetSpeedUWP.InternetConnectionState.connected) {
InetSpeedUWP.InternetConnectionState.getInternetConnectionSpeedWithHostName(
new Windows.Networking.HostName("mytargethost.com"))
.then(function (speed) {
if (speed === ConnectionSpeed.Unknown) return;
if (speed === ConnectionSpeed.High) {
//Highspeed, low latency Internet connection detected...
}
else if (speed === ConnectionSpeed.Average){
//Average speed, average latency Internet connection detected...
}
else if (speed === ConnectionSpeed.Low) {
//High latency, low speed Internet connection detected...
}
});
}
else {
//Not connected...
}
Example (C++/CX consumer):
C++
if (InternetConnectionState::Connected)
{
auto connectionSpeedWithHost = InternetConnectionState::GetInternetConnectionSpeedWithHostName(ref new Windows::Networking::HostName("pinterest.com"));
auto _speed = create_task(connectionSpeedWithHost);
_speed.then([this](ConnectionSpeed speed)
{
if (speed == ConnectionSpeed::Unknown) return;
TextBoxResults->Text += speed.ToString() + "\n" + "Raw Speed: " + InternetConnectionState::RawSpeed + "\n";
});
}
else
{
TextBoxResults->Text = "Not connected...";
}