Skip to main content
PeerFinder.DiscoveryData | discoveryData property

Gets or sets user or device data to include during device discovery.

Syntax


var discoveryData = Windows.Networking.Proximity.PeerFinder.discoveryData;
Windows.Networking.Proximity.PeerFinder.discoveryData = discoveryData;

public static IBuffer DiscoveryData { get; set; }

Public Shared Property DiscoveryData As IBuffer

public:
static property IBuffer^ DiscoveryData { 
   IBuffer^ get();
   void set (IBuffer^ value);
}

Property value

Type: IBuffer

User or device data to include during device discovery. Must be less than 32 bytes.

Remarks

Note  

Windows Phone Store apps: This property is not supported. Setting it has no effect and no data is returned from this property on a phone.

Examples


// Default to the peer role.
Windows.Networking.Proximity.PeerRole appRole = Windows.Networking.Proximity.PeerRole.Peer;
bool launchedByTap = false;

protected override void OnNavigatedTo(NavigationEventArgs e)
{
    LaunchActivatedEventArgs launchArgs = e.Parameter as LaunchActivatedEventArgs;

    if (launchArgs.Arguments.Contains("Windows.Networking.Proximity.PeerFinder:StreamSocket"))
    {
        launchedByTap = true;

        if (launchArgs.Arguments.Contains("Role=Host"))
        {
            appRole = Windows.Networking.Proximity.PeerRole.Host;
        }
        else if (launchArgs.Arguments.Contains("Role=Client"))
        {
            appRole = Windows.Networking.Proximity.PeerRole.Client;
        }
        else
        {
            appRole = Windows.Networking.Proximity.PeerRole.Peer;
        }
    }
}

bool started = false;

// Click event for "Advertise" button.
void AdvertiseForPeers(object sender, RoutedEventArgs e)
{
    if (!started)
    {
        Windows.Networking.Proximity.PeerFinder.DisplayName = DisplayNameTextBox.Text;

        if ((Windows.Networking.Proximity.PeerFinder.SupportedDiscoveryTypes &
             Windows.Networking.Proximity.PeerDiscoveryTypes.Triggered) ==
             Windows.Networking.Proximity.PeerDiscoveryTypes.Triggered)
        {
            Windows.Networking.Proximity.PeerFinder.TriggeredConnectionStateChanged +=
                TriggeredConnectionStateChanged;

            WriteMessageText("You can tap to connect a peer device that is " +
                             "also advertising for a connection.\n");
        }
        else
        {
            WriteMessageText("Tap to connect is not supported.\n");
        }

        if ((Windows.Networking.Proximity.PeerFinder.SupportedDiscoveryTypes &
             Windows.Networking.Proximity.PeerDiscoveryTypes.Browse) !=
             Windows.Networking.Proximity.PeerDiscoveryTypes.Browse)
        {
            WriteMessageText("Peer discovery using Wi-Fi Direct is not supported.\n");
        }

        // Set the peer role selected by the user.  
        if (launchedByTap)
        {
            Windows.Networking.Proximity.PeerFinder.Role = appRole;
        }
        else
        {
            switch (GetRoleFromUser())
            {
                case "Peer":
                    Windows.Networking.Proximity.PeerFinder.Role =
                        Windows.Networking.Proximity.PeerRole.Peer;
                    break;
                case "Host":
                    Windows.Networking.Proximity.PeerFinder.Role =
                        Windows.Networking.Proximity.PeerRole.Host;
                    break;
                case "Client":
                    Windows.Networking.Proximity.PeerFinder.Role =
                        Windows.Networking.Proximity.PeerRole.Client;
                    break;
            }
        }

        // Set discoveryData property with user supplied text. 
        var discData = GetDiscoveryDataFromUser();
        var writer = new Windows.Storage.Streams.DataWriter(
            new Windows.Storage.Streams.InMemoryRandomAccessStream());
        writer.WriteString(discData);
        Windows.Networking.Proximity.PeerFinder.DiscoveryData =
            writer.DetachBuffer();

        Windows.Networking.Proximity.PeerFinder.Start();
        started = true;
    }
}

// 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;
            else
                MessageBlock.Text += message;
        });
}

// Default to the peer role.
var appRole = Windows.Networking.Proximity.PeerRole.peer;
var launchedFromTap = false; 

app.onactivated = function (args) {
    if (args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) {
        Windows.Networking.Proximity.PeerFinder.addEventListener("connectionrequested", connectionRequested);

        // Detect if app launched from a tap.
        if ((args.detail.kind === Windows.ApplicationModel.Activation.ActivationKind.launch) &&
            (args.detail.arguments === "Windows.Networking.Proximity.PeerFinder:StreamSocket")) {

            launchedFromTap = true; 
 
            if (args.detail.arguments.search("Role=Host") !== -1) { 
                appRole = Windows.Networking.Proximity.PeerRole.host; 
            } 
            else if (args.detail.arguments.search("Role=Client") !== -1) { 
                appRole = Windows.Networking.Proximity.PeerRole.client; 
            } 
            else { 
                appRole = Windows.Networking.Proximity.PeerRole.peer; 
            } 
        } 
    }

    advertiseForPeers(true);

    args.setPromise(WinJS.UI.processAll());
}

var started = false;

// Click event for "Advertise" button.
function advertiseForPeers(launchedFromTap) {
    Windows.Networking.Proximity.PeerFinder.displayName = displayNameTextBox.Text;

    if (Windows.Networking.Proximity.PeerFinder.supportedDiscoveryTypes &
        Windows.Networking.Proximity.PeerDiscoveryTypes.triggered) {

        Windows.Networking.Proximity.PeerFinder.addEventListener(
            "triggeredconnectionstatechanged", triggeredConnectionStateChanged);

        id("messageDiv").innerHTML +=
            "You can tap to connect a peer device that is " +
            "also advertising for a connection.<br />";
    } else {
        id("messageDiv").innerHTML +=
            "Tap to connect is not supported.<br />";
    }

    if (!launchedFromTap) {
        if (!(Windows.Networking.Proximity.PeerFinder.SupportedDiscoveryTypes &
              Windows.Networking.Proximity.PeerDiscoveryTypes.Browse)) {
            id("messageDiv").innerHTML +=
                "Peer discovery using Wi-Fi Direct is not supported.<br />";
        }
    }       

    if (!started) {
        // Set the peer role selected by the user.  
        if (launchedByTap) { 
            Windows.Networking.Proximity.PeerFinder.role = appRole; 
        } 
        else { 
            switch (getRoleFromUser()) { 
                case "peer": 
                    Windows.Networking.Proximity.PeerFinder.role = 
                        Windows.Networking.Proximity.PeerRole.peer; 
                    break; 
                case "host": 
                    Windows.Networking.Proximity.PeerFinder.role = 
                        Windows.Networking.Proximity.PeerRole.host; 
                    break; 
                case "client": 
                    Windows.Networking.Proximity.PeerFinder.role = 
                        Windows.Networking.Proximity.PeerRole.client; 
                    break; 
            } 
        } 
 
        // Set discoveryData property with user supplied text. 
        var discData = getDiscoveryDataFromUser();
        var writer = Windows.Storage.Streams.DataWriter(
            new Windows.Storage.Streams.InMemoryRandomAccessStream()); 
        writer.writeString(discData); 
        Windows.Networking.Proximity.PeerFinder.discoveryData = 
            writer.detachBuffer(); 

        Windows.Networking.Proximity.PeerFinder.start();
        started = true;
    }
}

Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0 [for Xbox, see UWP features that aren't yet supported on Xbox]

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

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

Minimum supported client

Windows 8.1

Minimum supported server

Windows Server 2012 R2

Minimum supported phone

None supported

Namespace

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

Metadata

Windows.winmd

See also

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