Share via

Windows.Networking.Proximity Namespace

Contains classes that support connections between devices that are within close range.



Contains properties that are passed to an application with the ConnectionRequested event.


Enables you to discover other instances of your app on nearby devices and create a socket connection between the peer apps by using a tap gesture or by browsing. For creating Bluetooth socket connections on Windows 8.1 and later, use Windows.Devices.Bluetooth.Rfcomm instead.


Contains information that identifies a peer.


Dynamically discovers peer apps within wireless range.


Enables you to publish messages to proximate devices or subscribe to messages from proximate devices.


Represents a message that's received from a subscription.


Contains properties that the TriggeredConnectionStateChanged event passes to an application.



Indicates which discovery options are available to use with the PeerFinder class.


Describes the role of the peer app when connected to multiple peers.


Describes the status of a PeerWatcher object.


Indicates the current state of a connection to a peer application.



Describes the method that handles the DeviceArrived event.


Describes the method that handles the DeviceDeparted event.


Describes the method that will handle the event that's fired when a message that has been subscribed to has been received.


Describes the method that will handle the event that's fired when a published message has been transmitted.


This example shows how you can use the ProximityDevice class to determine when a device enters and leaves proximity.

Windows.Networking.Proximity.ProximityDevice proximityDevice;

private void InitializeProximityDevice()
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

    if (proximityDevice != null) {
        proximityDevice.DeviceArrived += ProximityDeviceArrived;
        proximityDevice.DeviceDeparted += ProximityDeviceDeparted;

        WriteMessageText("Proximity device initialized.\n");
        WriteMessageText("Failed to initialized proximity device.\n");

private void ProximityDeviceArrived(Windows.Networking.Proximity.ProximityDevice device)
    WriteMessageText("Proximate device arrived. id = " + device.DeviceId + "\n");

private void ProximityDeviceDeparted(Windows.Networking.Proximity.ProximityDevice device)
    WriteMessageText("Proximate device departed. id = " + device.DeviceId + "\n");

// Write a message to MessageBlock on the UI thread.
private Windows.UI.Core.CoreDispatcher messageDispatcher = Window.Current.CoreWindow.Dispatcher;

async private void WriteMessageText(string message, bool overwrite = false)
    await messageDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
        () =>
            if (overwrite)
                MessageBlock.Text = message;
                MessageBlock.Text += message;
Dim proximityDevice As Windows.Networking.Proximity.ProximityDevice

Private Sub InitializeProximityDevice()

    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault()

    If proximityDevice IsNot Nothing Then
        AddHandler proximityDevice.DeviceArrived, AddressOf ProximityDeviceArrived
        AddHandler proximityDevice.DeviceDeparted, AddressOf ProximityDeviceDeparted

        WriteMessageText("Proximity device initialized." & vbTab)
        WriteMessageText("Failed to initialized proximity device." & vbTab)
    End If
End Sub

Private Sub ProximityDeviceArrived(device As Windows.Networking.Proximity.ProximityDevice)
    WriteMessageText("Proximate device arrived. id = " & device.DeviceId & vbTab)
End Sub

Private Sub ProximityDeviceDeparted(device As Windows.Networking.Proximity.ProximityDevice)
    WriteMessageText("Proximate device departed. id = " & device.DeviceId & vbTab)
End Sub

' Write a message to MessageBlock on the UI thread.
Private Async Sub WriteMessageText(message As String, Optional overwrite As Boolean = False)
    Await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
            If overwrite Then
                MessageBlock.Text = message
                MessageBlock.Text &= message
            End If
        End Sub)
End Sub


You can use proximity to connect computers by using a simple tap gesture. If two computers come within 3 centimeters to 4 centimeters of each other, or are tapped together, the operating system of each computer detects the other computer. You can then connect the two computers to share content or publish and subscribe to messages. Proximity also supports discovery of peer devices via Wi-Fi Direct.


The proximity APIs do not provide authentication, encryption, or message integrity. Do not use proximity to exchange user sensitive information such as passwords, financial data, text messages, email, photographs, or government id numbers.

See also