The Universal Windows Platform (UWP) has a diverse set of networking APIs to enable developers to implement a wide range of scenarios. For many networking scenarios, there are multiple options available - Which API should a developer use for a given scenario? What are the tradeoffs of using one over the other? This talk helps answer these questions by walking through some broad networking scenarios and discussing how to choose the right API for each of them.
3. HTTPS with user authentication
Device-Cloud bi-directional communication
Network communication between devices over sockets
Download/Upload content to cloud in the background
4.
5.
6. Feature Windows.Web.Http System.Net.Http
Programming Language support All UWP languages C#/VB
Private CA/Self-signed certificate √ √
Custom validation of server certificate √ (new!) X (on roadmap)
Integration with native UI for Auth √ X
Client Certificate Support √ Partial
Cross-platform support (Xamarin) X √
7. var filter = new
HttpBaseProtocolFilter();
filter.ClientCertificate =
myCertificate;
var client = new HttpClient(); OR
var client = new HttpClient(filter);
HttpResponseMessage response =
await client.GetAsync(uri);
8. Demo: Online Auction App
Requirements:
1. Custom server certificate validation
2. Client Certificate
API Choice:
Windows.Web.Http.HttpClient
13. Feature MessageWebSocket StreamWebSocket
Message Format Discrete WebSocket
messages
Continuous data
stream
UTF-8 Strings/JSON data √ X
Binary data √ √
Recommended data size Small (bytes/KB) Large (MB)
Recommended content types Strings, JSON content Audio, Video, Photos
14. var socket= new MessageWebSocket();
socket.MessageReceived =
myReceivingHandler;
socket.Closed = myClosedHandler;
await socket.ConnectAsync(serverUri);
// Send data.
socket.Close(code, reason);
15. Demo: Online Auction App
Requirements:
1. Client-Server bidirectional communication
2. Server relays others’ bids independent of client’s bids
3. Minimum latency and overhead
API Choice:
Windows.Networking.Sockets.MessageWebSocket
16. Wireshark trace for WebSocket run
Wireshark trace for HttpClient run
Bytes on the wire
23. Things to note:
• At any point ownership of the socket can be only in one component
• Find the list of sockets owned by the service using:
SocketActivityInformation.AllSockets
• Socket not in the list means socket is already closed or retrieved
socket.TransferOwnership(socketId);
24. Demo: Multi-player Game
Requirements:
1. App communication between devices over sockets
2. Listening on the socket activity even when the app is not
running
API Choice:
Windows.Networking.Sockets
25.
26.
27.
28. Feature HttpClient in BG Task Windows.Networking.
BackgroundTransfer
Protocol HTTP HTTP/FTP
Destination Location In memory & File File only
Recommended file size Small (KBs) Large (MBs)
Resiliency (network connection
drop/reboot)
Needs additional code Can be resumed
where left off
Network Cost Awareness Needs additional code Built-in
Battery Saver Awareness Needs additional code Built-in
31. Demo: Multi-player Game
Requirements:
1. Download a new game level in the Background
2. Show a toast notification on completion of the download
API Choice:
Windows.Networking.BackgroundTransfer