Windows Dev Center

UWP Communication APIs

Explore the powerful APIs available for enabling seamless communication within your Universal Windows Platform (UWP) applications. From local inter-process communication to network-based messaging, UWP provides robust solutions to connect your app components and interact with other devices and services.

Key Communication Scenarios

Featured Communication APIs

Windows.Networking.Sockets Namespace

Provides classes for network communication, including TCP, UDP, and WebSockets. Ideal for building connected experiences.

  • StreamSocket: For establishing reliable TCP connections.
  • DatagramSocket: For sending and receiving UDP datagrams.
  • MessageWebSocket: For real-time, bidirectional communication over WebSockets.

Learn more about StreamSocket

// Example: Basic TCP client connection
using Windows.Networking.Sockets;
using System.Threading.Tasks;

var socket = new StreamSocket();
await socket.ConnectAsync(new Windows.Networking.HostName("example.com"), "80");
// ... send and receive data ...

Windows.ApplicationModel.Background.BackgroundTask

Allows your application to perform tasks in the background, including responding to network events or incoming messages.

Learn more about Background Tasks

// Example: Registering a background task for network notifications
var builder = new BackgroundTaskBuilder();
builder.TaskEntryPoint = "MyBackgroundTasks.NetworkTask";
builder.SetTrigger(new MaintenanceTrigger(MaintenanceInterval.Day, MaintenanceTriggerKind.BackgroundUpload));
var registration = builder.Register();

Windows.Networking.Proximity Namespace

Enables proximity-based interactions, such as discovering and communicating with nearby devices using technologies like Bluetooth and NFC.

  • PeerFinder: For discovering and connecting with other devices.
  • ConnectionRequestedEventArgs: Information about a connection request.

Learn more about PeerFinder

Windows.ApplicationModel.Core.AppServiceConnection

Facilitates communication between UWP apps through app services, allowing one app to provide functionality to another.

Learn more about App Services

// Example: Sending a message to an app service
var connection = new AppServiceConnection();
connection.PackageFamilyName = "AnotherAppPackageFamilyName";
connection.AppServiceName = "MyDataService";

var (status, response) = await connection.SendMessageAsync(new ValueSet { { "command", "getData" } });
if (status == AppServiceResponseStatus.Success) {
    // Process response.Result
}