In today's era of cloud-first, mobile-first technology, most apps have at least some integration with Web services or other devices on the network. These include apps that get weather online content, news or sports scores, media or downloaded podcasts, or even peer-to-web games, chat or VoIP apps. These applications work together to build a common application platform by using a variety of network APIs. In Windows 10, our network team put in a lot of effort to improve the speed and memory performance of developers in terms of functionality and flexibility when using these network APIs. In this blog post, we will discuss some of the key improvements we have made in this area and show you how to take advantage of these new features in your own applications.
Network APIs under the common Application Platform:The Universal Windows Platform (UWP) contains a large set of network APIs, primarily for different scenarios, from querying the connection status of a device to connecting to a peer device, communicating with restful Web services, and downloading large media files in the background. In this blog post, we will focus on a subset of the following network APIs:
- Windows.Networking.Sockets – typically used in peer-to-peer chat, VoIP, VPN applications
- System.Net.Sockets –. NET version of the network sockets API, primarily for cross-platform libraries and applications
- WinSock – widely used in cross-platform libraries, such as OpenSSL or multiplayer games libraries
- Windows.Web.Http and System.Net.Http – for communicating with rest Web services
- Windows.Networking.BackgroundTransfer – Used to upload or download data even if the application is not in the foreground
- Windows.Data.Json – Json content for serialization/deserialization is serviced by a Web service
These APIs represent different network sockets layers at the bottom, and HTTP is built on top of it. Finally, background transfers and JSON add more value to the build over HTTP.
new features of the network API in WINDOWS10:In Windows 10, the above APIs have enhanced performance and provided developers with greater flexibility. We discussed all of these improvements in detail in build 2015 video.
- Socket Broker: Allows the application to listen for sockets, even when the application is running in the background;
- batched sends: A new optimization implemented in the socket API that can send data at speeds up to 4x;
- HTTP/2: The newer HTTP API supports the new, faster version of the HTTP protocol for UWP applications. This allows rest Web services to download and upload up to 3x of speed;
- post-processing in Background Transfer: UWP apps can now handle download/upload in background tasks, even when the application is next started.
Due to time limitations, we cannot cover all new features in the video that we added to Windows 10. Here are a few more:
System.Net.Sockets and Winsock for UWP Apps:For UWP application developers, WINDOWS10, System.Net.Sockets, and Winsock have been added to the API for applications in the Windows Store (they also apply to Windows Phone Silverlight apps), these APIs are very often used in a very high frequency. In Visual Studio2014, Winsock also supports Windows8.1. Winsock and System.Net.Sockets in the current UWP are based on phone 8.1 Silverlight, and continue to support most types, properties and methods (some of the APIs that are considered obsolete have been removed.) )。
The client certificate supports the streaming socket class:The Windows.Networking.StreamSocket class supports authentication interactions between servers and applications by using a using SSL/TLS. In some cases, the application also needs to authenticate itself to the server by using a TLS client certificate. At the beginning of WINDOWS10, you can provide a client certificate in a streaming socket that controls the object (it must be started before the TLS handshake protocol). If a client's certificate is requested by the server side, Windows will do so by raising the certificate. Here is a code snippet showing how to implement this scenario:
1 var New Streamsocket (); 2 Windows.Security.Cryptography.Certificates.Certificate 3 await Getclientcert (); 4 socket. Control.clientcertificate = certificate; 5 await socket. ConnectAsync (Destination,6 socketprotectionlevel.tls12);
JSON has a better debugging experience when working with null values:A key developer asked us to improve the handling of NULL for the Windows.Data.Json API in Windows 8.1. Along with WINDOWS10, we have added a new, more intuitive API to serialize and deserialize null values with JSON strings. The following is an example of how a UWP application in Windows 10 handles null values in a JSON string: object is serialized as JSON (stringify):
1 Jsonobject[key] = jsonvalue.createnullvalue (); 2 var outputstring = jsonobject.stringify ();
Deserialize a JSON string (Parse):
1 ijsonvalue myjsonvalue = Jsonobject.getnamedvalue (key); 3 if (myjsonvalue.valuetype == Jsonvaluetype.null) { 5 Phone = null " 7 else 8 { 9 var myvalue = myjsonvalue.getstring (); 10 }
The new enumeration type value Jsonvaluetype.null allows developers to handle Null by using values of Integer, String, and Boolean types in the same programmatic manner.
JSON's rich debugging experience in Visual Studio:The next thing we need to introduce is Windows.Data.Json's rich debugging experience in Visual Studio. In Windows8.1, developers can see only one type of jsonobject or Jsonarray instance, rather than the entire contents of it, by stepping through debugging. This makes it more difficult for developers to debug parsing logic and ensure that it is populated correctly. With WINDOWS10, you can now check the contents of the internal jsonobject and Jsonarray types. Here is an example with the Jsonarray object:
improved SD card supports background transfer:In Windows8.1, the Windows.Networking.BackgroundTransfer API supports downloading data to a removable storage device, such as an SD card, in effect downloading the data as an internal temporary cache before moving the data to the specified location. The result is that the size of the file that can be downloaded limits the amount of memory available. In Windows10, the old implementation is changed to check that the download is occurring on a different drive instead of in the Setup program, and that the temporary cache location will be used. This will solve the problem of not downloading large files on the SD card (the data to be downloaded is much larger than the application's memory storage).
links to articles related to this:
- . NET Networking APIs for UWP–HTTP://AKA.MS/DOTNETUWP
- windows.devices.alljoyn–https://channel9.msdn.com/events/build/2015/2-623
- Wi-Fi and Network Connectivity apis–https://channel9.msdn.com/events/build/2015/2-86
- Wi-Fi Direct apis–https://channel9.msdn.com/events/build/2015/3-98
- Hotspot 2.0 api–https://channel9.msdn.com/events/build/2015/2-80
- Bluetooth apps–https://channel9.msdn.com/events/build/2015/3-739
- IoT & Azure integration–https://channel9.msdn.com/events/build/2015/2-67
Note: Turn to original
as part of the translation is not fully translated in accordance with the original text, all may be different from the original, but also please bo friends criticize and correct!!
[Turn to translate] Networking API improvements in Windows 10