Updated November 7, 2014 11:39 pm - The network APIs have tremendous depth and enable your app to work in many ways. But it can be hard to figure out how and when to use the different APIs. To help you out, the Windows Networking Team has created poster-sized cheat sheets with overviews and code samples of the most popular network APIs. And, we’re working on more!
The cheat sheets tell you about the different APIs. But which API is the right one to use, and when? Here’s an easy way to figure it out:
- Are you connecting to an HTTP server?
- For small, interactive transfers and to connect to web services for a mash-up type app, use the Windows.Web.Http HttpClient family of APIs.
- For larger transfers, or transfers that work even when your app is suspended, use the Windows.Networking.BackgroundTransfer classes. It can also do FTP transfers.
- To pre-load data for your app, you can use Windows.Networking.BackgroundTransfer.ContentPrefetcher (which also works with the HttpClient classes)
- Are you connected to a classic TCP or UDP server? Or to Bluetooth? Use the Windows.Networking.StreamSocket (TCP and Bluetooth) or DatagramSocket (UDP and Multicast) classes.
- Are you connecting to one of the new “WebSocket” servers? They aren’t classic sockets (and don’t interoperate with classic sockets), but they can tunnel through corporate proxies and interoperate with up-to-date HTML5 browsers. Websockets are in the Windows.Networking.Sockets namespace.
- Are you connecting to people in the same room? (For example, with Near Field Communication (NFC) tap to connect)? If so, use the Windows.Networking.Proximity PeerFinder and related classes; this can give you back a StreamSocket that you can use to communicate with peers.
Our first pack of cheat sheets are for the HttpClient, Sockets, and Background Transfer APIs. Download the pack now from the Microsoft Download Center. And let us know what other cheat sheets you need!
–Peter Smith, Program Manager, Windows Networking Team