Send and receive data with TCP or UDP sockets in your Windows Store app using features in the Windows.Networking.Sockets namespace.
Sockets provide a low-level interface for sending and receiving network data. The primary classes for use with sockets include the following:
- DatagramSocket - Used to support network communication using a UDP datagram socket.
- StreamSocket - Used to support network communication using a TCP stream socket.
- StreamSocketListener - Used to support listening for an incoming network connection using a TCP stream socket.
The primary classes listed above also have a number of related support classes in the Windows.Networking.Sockets namespace used with these classes.
Consider using the following protocols based on your app's requirements.
|If your app||Use|
Connects to a network service that uses an existing protocol (SMTP, POP, IMAP, or MAPI for mail, for example) that is not directly supported by other networking features
TCP or UDP sockets
Connects to another machine on the same local network
TCP or UDP sockets
Requires a simple request\response protocol that can communicate through HTTP proxies.
Representational State Transfer (REST) APIs that are available using C#, VB.NET, and C++
Requires socket-like semantics (asynchronous, bi-directional transfers) to connect across the Web, including through HTTP proxies.
|Quickstart: Connecting to a network resource with a stream socket||
Learn how to connect to a network resource with a stream socket using TCP to send and receive data.
|Quickstart: Connecting to a network resource with a datagram socket||
Learn how to connect to a network resource with a datagram socket using UDP to send and receive data.
|How to use advanced socket controls|
|How to secure socket connections with TLS/SSL||
Learn how to secure socket connections with TLS/SSL when using a StreamSocket.
|How to set timeouts on socket operations||
Learn how to set timeouts on network socket operations to limit the time to wait for an operation to complete.
The network isolation feature in Windows 8 enables a developer to control and limit network access by a Windows Store app. Not all apps may require access to the network. However for those apps that do, the Windows 8 provides different levels of access to the network that can be enabled by selecting appropriate capabilities.
Network isolation allows a developer to define for each app the scope of required network access. An app without the appropriate scope defined is prevented from accessing the specified type of network, and specific type of network request (outbound client-initiated requests or both inbound unsolicited requests and outbound client-initiated requests). The ability to set and enforce network isolation ensures that if an app does get compromised, it can only access networks where the app has explicitly been granted access. This significantly reduces the scope of the impact on other applications and on Windows.
Network isolation affects any class elements in the Windows.Networking.Sockets and related namespaces that try to access the network. Windows actively enforces network isolation. A call to a class element in the Windows.Networking.Sockets namespace that results in network access may fail because of network isolation if the appropriate network capability has not been enabled.
The network capabilities for an app are configured in the app manifest when the app is built. Network capabilities are usually added using Microsoft Visual Studio 2012 when developing the app. Network capabilities may also be set manually in the app manifest file using a text editor.
For more detailed information on network isolation, see the How to configure network isolation capabilities.
- Other resources
- Adding support for networking
- Connecting with sockets (Windows Store apps using C#/VB/C++ and XAML)
- Connecting with WebSockets
- How to configure network isolation capabilities
- How to set background connectivity options
- Troubleshoot and debug network connections
- DatagramSocket sample
- StreamSocket sample
Build date: 11/16/2013