Connecting with sockets (Windows Store apps using C#/VB/C++ and XAML)

Language: JavaScript and HTML | VB/C#/C++ and XAML
1 out of 7 rated this helpful - Rate this topic

Purpose

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.

Developer audience

Designed for use by developers using VB/C#/C++ and XAML interested in enabling the use of sockets for network communications in their Windows Store app. This feature includes TCP and UDP sockets including UDP multicast to enable developers to implement other higher-layer networking protocols. TCP and UDP sockets can be used by an app to make client connections, to listen for connections and operate as a server, or for both client and server operations.

Consider using the following protocols based on your app's requirements.

If your appUse

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.

WebSockets

 

Sockets are supported by the classes in the Windows.Networking.Sockets and Windows.Networking namespaces.

Windows 8 also introduces a new type of socket, a WebSocket. For more information, see Connecting with WebSockets and the MessageWebSocket and StreamWebSocket classes.

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, Windows 8 provides different levels of access to the network that can be enabled by selecting appropriate capabilities. 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.

In this section

TopicDescription

Quickstart: Connecting with a stream socket

This topic shows how to enable a Windows Store app to send and receive data with a TCP stream socket using a StreamSocket.

Quickstart: Connecting with a datagram socket

This topic shows how to enable a Windows Store app to send and receive data with a UDP datagram socket using a DatagramSocket. This type of socket can be used to send and receive network packets with low overhead, but reception of the data is not guaranteed.

How to use advanced socket controls

This topic shows how to enable a Windows Store app to set advanced socket options on the DatagramSocket, StreamSocket, StreamSocketListener features.

How to secure socket connections with TLS/SSL

This topic shows how to enable a Windows Store app to secure stream socket connections with TLS/SSL when using the StreamSocket feature.

How to set timeouts on socket operations

This topic shows how to set timeouts on network socket operations in a Windows Store app to limit the time to wait for an operation to complete.

 

Related topics

Other resources
Adding support for networking
Connecting with sockets(Windows Store apps using JavaScript and HTML)
Connecting with WebSockets
How to configure network isolation capabilities
Staying connected in the background
Troubleshoot and debug network connections
Reference
Windows.Networking
Windows.Networking.Connectivity
Windows.Networking.Sockets
Samples
ControlChannelTrigger StreamWebSocket sample
StreamSocket sample

 

 

Build date: 3/12/2013

Did you find this helpful?
(1500 characters remaining)
© 2013 Microsoft. All rights reserved.