Networking API Improvements in Windows 10

In today’s cloud-first, mobile-first technology world, most Store apps have at least some integration with web services or other devices on a network. These include apps that fetch online weather content, news or sports scores, media or podcast downloaders and even peer-to-peer games, chat or VoIP apps. These apps are built using a wide variety of networking APIs that are a part of the Universal Windows Platform.

In Windows 10, our networking team has invested significant effort in improving these APIs in terms of their speed and memory performance as well as the capabilities and flexibility they provide to you, the developer. In this blog post, we’ll discuss some of the key improvements we have made in this area, and illustrate how to leverage these in your own apps.

Networking APIs in Universal Windows Platform

The Universal Windows Platform (UWP) contains a large set of networking APIs that are targeted at diverse scenarios – from querying the connectivity status of the device and connecting to peer devices, to communicating with REST web services and downloading large media files in the background. In this blog post, we’ll focus on the following subset of networking APIs:

System.Net.Sockets – .NET version of Sockets API widely used in cross-platform libraries and apps

WinSock – Widely used in cross-platform libraries such as OpenSSL or multiplayer game libraries

Windows.Web.Http and System.Net.Http – Used to communicate with REST web services

Windows.Networking.BackgroundTransfer – Used for uploading or downloading data even when app is not in the foreground

Windows.Data.Json – Used to serialize/deserialize JSON content served by webservices

These APIs represent different layers in networking from Sockets at the lowest layer, HTTP building on top of it and finally, Background Transfer and JSON that add more value building on top of HTTP.

New in Windows 10

In Windows 10, the above-mentioned APIs have been enhanced for greater performance and for providing more flexibility to developers. We discussed all of these improvements in detail in this video for BUILD 2015.

Socket Broker: Allows apps to listen on Sockets even when the app is not in the foreground

Batched Sends: A new optimization in the Sockets API implementation can make sending data up to 4x faster.

HTTP/2: HTTP APIs now support the new, faster version of HTTP protocol for UWP apps. This makes REST webservice downloads and uploads up to 3x faster.

Post-processing in Background Transfer: UWP apps can now handle the completion of their background downloads/uploads in a background task even before the app is launched the next time.

Due to time constraints, we couldn’t cover all of the new features we’re adding to Windows 10 in the video. Here are a few more:

System.Net.Sockets and Winsock for UWP Apps

With Windows 10, System.Net.Sockets and Winsock have been added into the API surface for UWP app developers. These were both highly requested APIs for Windows Store apps (they were already available for Windows Phone Silverlight apps). WinSock is also supported for Windows 8.1 apps with the latest updates to Visual Studio 2014.

The current API surface of both Winsock and System.Net.Sockets for UWP apps is based on that of Phone 8.1 Silverlight and continues to support most of the types, properties and methods (some APIs that are considered obsolete have been removed).

Client certificate support for StreamSocket class

Windows.Networking.StreamSocket class supports using SSL/TLS to authenticate the server the app is talking to. In certain cases, the app also needs to authenticate itself to the server using a TLS client certificate. Starting in Windows 10, you can provide a client certificate on the StreamSocket.Control object (this must be set before the TLS handshake is started). If the server requests the client certificate, Windows will respond with the certificate provided.

Handling null values and better debugging experience for JSON

One of the key developer requests we had for our Windows.Data.Json API in Windows 8.1 was to enable better handling of null values. Starting with Windows 10, we have added new, intuitive APIs to serialize and deserialize null values to and from JSON strings. Here is an example of how you can handle null value in JSON strings in Windows 10 UWP apps:

The new JsonValueType.Null enumeration value enables handling of null values with the same programming patterns that developers use today for integers, strings or Boolean values.

Richer debugging experience in Visual Studio for JSON

The next addition to Windows.Data.Json API is an improved debugging experience with Visual Studio. In Windows 8.1, developers stepping through their code while debugging would only see the type of a JsonObject or JsonArray instance but not its contents. This makes it harder for developers to debug their parsing logic and ensure that their objects have been correctly populated. Starting in Windows 10, you can now inspect the internal contents of JsonObject and JsonArray types. Here’s an example with a JsonArray object:

Improved SD card support for Background Transfer

In Windows 8.1, the Windows.Networking.BackgroundTransfer API supported downloading data on a removable storage (e.g. SD Card). The design was to download the content in the internal temporary cached storage first and then move the file to the destination. As a result, the size of the file which can be downloaded was constrained by the amount of internal storage available.

In Windows 10, this implementation has been changed to check whether the download is happening in a different drive than where the application is installed and use that location for the temporary cache. This will alleviate the problem of not being able to download large content (content which is greater in size than the available internal storage) on SD card.

Related Content

The entire set of networking APIs in UWP is too large to cover here. You can watch the following videos from Build 2015 for more info on other APIs in the networking area:

Looking Ahead

With Windows 10, we have evolved our networking APIs from Windows 8.1 to provide better performance and capabilities to you, the developer. Further, since these APIs are a part of UWP, you can use them to build apps for the entire range of Windows devices. With upcoming releases, we will continue to improve the performance of our networking APIs as well as add features that enable developers to build awesome, differentiated experiences on Windows. We look forward to hearing your feedback on which networking APIs are currently missing from UWP and are highest priority for you to deliver your app on Windows. You can file an idea on UserVoice or join the Windows Insiders program and submit feedback through the forums.

Yes – Bruno is right. Socket broker enables you to listen on a socket in the background. For torrents, you will need to implement the protocol yourself on top of a socket. Of course, the background task would be subject to the standard resource budgets for background operations.

Peter – this post is about new features we have added to our networking APIs to enable developers to build more performant and full-featured apps. It’s unlikely that this will affect your local network presence.
I am assuming you are part of the Windows Insider program? For such issues, please use the in-built Windows Feedback to report a bug.

I wish I could set SocketProtectionLevel.Tls12 for Windows.Web.Http.HttpClient, but good that the socket can set the client certificate now. I can use that to implement my own http filter instead of going C++.

Can you provide more details as to what you mean by an SIP client? Assuming that you were looking for a way for your app to listen for incoming messages even when the app is not alive, then Yes – Socket Broker does enable that scenario.

Sip is a VOIP protocol defined in https://tools.ietf.org/html/rfc3261
It is used by quite a few telephone companies even for the last mile, as it is basically telefon via internet.
Android has a working SIP Client in the OS since 2.3, so I can use it as my main phone at home.

ATM you can’t write a SIP Client for WP 8.1 as it has to be open and in front to listen on a port.

If Socket Broker would work in UWP apps on WM10 then we could have a real SIP Client there to.

Hello!
I would like to know if the Socket Broker is already build in windows 10 for mobile? I ask because I am very interested in having a sip client to get phone calls on wlan even when the phone app is closed. I have windows 10 mobile on my lumia but I can’t find this feature so I think it isn’t build in? Or is it?