Windows Dev Center

PeerWatcher class

Dynamically discovers peer apps within wireless range.


var peerWatcher = PeerFinder.CreateWatcher();


The PeerWatcher class has these types of members:


The PeerWatcher class has these events.

Added Occurs when a peer app is found within wireless range.
EnumerationCompleted Occurs after a scan operation is complete and all peer apps within wireless range have been found.
Removed Occurs when a peer app is no longer within wireless range.
Stopped Occurs when the PeerWatcher object has been stopped.
Updated Occurs when the DisplayName or DiscoveryData for a peer app within wireless range has changed.



The PeerWatcher class has these methods. With C#, Visual Basic, and C++, it also inherits methods from the Object class.

Start Begin dynamically searching for peer apps within wireless range.
Stop Stop dynamically searching for peer apps within wireless range.



The PeerWatcher class has these properties.

PropertyAccess typeDescription


Read-onlyGets the current state of the PeerWatcher object.



You can use the FindAllPeersAsync method to get a list of all peers within range. However, the FindAllPeersAsync method scans for peers once and then completes. Alternatively, you can use the PeerWatcher class to scan for peers and get updates as they are found and incrementally update your list of available peer apps. The PeerWatcher continuously scans for new peer apps within range and removes stale peer apps. You can update your list of peer apps by handling the Added event, which occurs when a new peer app is found, and the Removed event which occurs when a stale peer app is removed. The PeerWatcher continues to scan until you call the Stop method, or the PeerFinder.FindAllPeersAsync or PeerFinder.ConnectAsync methods.

Note   For Windows Phone Store apps, calling PeerFinder.ConnectAsync from within an EnumerationCompleted, Added or Updated event handler will fail. Instead, call it outside of these event handlers, for example, when the user has explicitly chosen to connect to a peer.

To create an instance of the PeerWatcher class, call the PeerFinder.Start method, and then call the CreateWatcher method.

var _peerWatcher;
var _peerWatcherIsRunning = false;
var _peerFinderStarted = false;

// The list of peers discovered by the PeerWatcher.
var _discoveredPeers = new Array();

function peerFinder_StartPeerWatcher() {
    if (!_peerFinderStarted) {
        // PeerFinder must be started first.

    if (_peerWatcherIsRunning) {
        // PeerWatcher is already running.

    try {
        if (!_peerWatcher)
            _peerWatcher = PeerFinder.createWatcher();

            // Add PeerWatcher event handlers. Only add handlers once.
            peerWatcher.addEventListener("added", peerWatcher_Added); 
            peerWatcher.addEventListener("removed", peerWatcher_Removed); 
            peerWatcher.addEventListener("updated",  peerWatcher_Updated); 
            peerWatcher.addEventListener("enumerationcompleted", peerWatcher_EnumerationCompleted); 
            peerWatcher.addEventListener("stopped", peerWatcher_Stopped); 

        // Empty the list of discovered peers.
        _discoveredPeers = new Array();

        // Start the PeerWatcher.

        _peerWatcherIsRunning = true;
    catch (ex)
        // Exceptions can occur if PeerWatcher.Start is called multiple times or
        // PeerWatcher.Start is called the PeerWatcher is stopping.
function cleanup() {
    if (_peerWatcher) {
        // Remove event handlers.
        peerWatcher.removeEventListener("added", peerWatcher_Added); 
        peerWatcher.removeEventListener("removed", peerWatcher_Removed); 
        peerWatcher.removeEventListener("updated", peerWatcher_Updated); 
        peerWatcher.removeEventListener("enumerationCompleted", peerWatcher_EnumerationCompleted); 
        peerWatcher.removeEventListener("stopped", peerWatcher_Stopped); 

        _peerWatcher = null;

Requirements (Windows 10 device family)

Device family


API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0


Windows::Networking::Proximity [C++]



Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8.1 [Windows Store apps only]

Minimum supported server

Windows Server 2012 R2 [Windows Store apps only]

Minimum supported phone

Windows Phone 8.1 [Windows Phone Silverlight 8.1 and Windows Runtime apps]


Windows::Networking::Proximity [C++]





See also

Proximity and Tapping (JavaScript)
Proximity and Tapping (C#/VB/C++)
Proximity sample



© 2015 Microsoft