Windows Dev Center

PeerFinder Class

Ermöglicht die Ermittlung einer anderen Instanz der App auf einem umliegenden Gerät und die Herstellung einer Socketverbindung zwischen den Peer-Apps mithilfe einer Tippgeste oder Navigation.

Syntax


var peerFinder = Windows.Networking.Proximity.PeerFinder;

Attribute

[MarshalingBehavior(Agile)]
[Threading(Both)]
[Version(0x06020000)]

Member

PeerFinderKlasse hat diese Membertypen:

Ereignisse

PeerFinderKlasse hat diese Ereignisse.

EreignisBeschreibung
ConnectionRequested Occurs when a remote peer requests a connection using the ConnectAsync method.
TriggeredConnectionStateChanged Occurs during a tap gesture from a remote peer.

 

Methoden

The PeerFinder Klasse hat diese Methoden. Mit C#, Visual Basic und C++ erbt es auch Methoden aus Object Klasse.

MethodeBeschreibung
ConnectAsync Connects to a peer discovered by a call to the FindAllPeersAsync method.
CreateWatcher Creates a new instance of a PeerWatcher object for dynamic discovery of peer apps.
FindAllPeersAsync Asynchronously browses for peer computers that are running the same app within wireless range.
Start() Starts the process of finding peer apps and makes an app discoverable to remote peers.
Start(String) Delivers a message to a peer app on a proximate device.
Stop Stops the process of finding peer apps or advertising for a peer connection.

 

Eigenschaften

Der PeerFinderKlasse hat diese Eigenschaften.

EigenschaftZugriffstypBeschreibung

AllowBluetooth

Lese-/SchreibzugriffSpecifies whether the PeerFinder class may connect a StreamSocket object by using Bluetooth.

AllowInfrastructure

Lese-/SchreibzugriffSpecifies whether the PeerFinder class may connect to a StreamSocket object using TCP/IP.

AllowWiFiDirect

Lese-/SchreibzugriffSpecifies whether the PeerFinder class may connect a StreamSocket object by using Wi-Fi Direct.

AlternateIdentities

SchreibgeschütztGets a list of alternate appId values to match with peer applications on other platforms.

DiscoveryData

Lese-/SchreibzugriffGets or sets the name that identifies your computer to remote peers.

DisplayName

Lese-/SchreibzugriffGets or sets the name that identifies your computer to remote peers.

Role

Lese-/SchreibzugriffGets or sets the role of the app in peer-to-peer connections.

SupportedDiscoveryTypes

SchreibgeschütztGets a value that indicates which discovery options are available to use with the PeerFinder class.

 

Hinweise

Wichtig  

Die Proximity-APIs bieten keine Authentifizierung, Verschlüsselung oder Nachrichtenintegrität. Verwenden Sie keine Nahverbindungen, um vertrauliche Benutzerinformationen wie Kennwörter, Finanzdaten, Textmeldungen, E-Mails, Fotos oder Personalausweisnummern auszutauschen.

Beispiele


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) {
        Windows.Networking.Proximity.PeerFinder.start();
        started = true;
    }
}

function triggeredConnectionStateChanged(e) {
    if (e.state === Windows.Networking.Proximity.TriggeredConnectState.peerFound) {
        id("messageDiv").innerHTML +=
            "Peer found. You may now pull your devices out of proximity.<br />";
    }
    if (e.state === Windows.Networking.Proximity.TriggeredConnectState.completed) {
        id("messageDiv").innerHTML += "Connected. You may now send a message.<br />";
        sendMessage(e.socket);
    }
}


// Click event for "Browse" button.
function findPeers() {
    if (Windows.Networking.Proximity.PeerFinder.supportedDiscoveryTypes &
        Windows.Networking.Proximity.PeerDiscoveryTypes.browse) {

        Windows.Networking.Proximity.PeerFinder.findAllPeersAsync().done(
    function (peerInfoCollection) {
        if (peerInfoCollection.length > 0) {
            // Connect to first peer found - example only.
            // In your app, provide the user with a list of available peers.
            connectToPeer(peerInfoCollection[0]);
        }
    },
    function (err) {
        id("messageDiv").innerHTML += "Error finding peers: " + err + "<br />";
    });
    } else {
        id("messageDiv").innerHTML +=
        "Peer discovery using Wi-Fi Direct is not supported.<br />";
    }
}

function connectToPeer(peerInfo) {
    id("messageDiv").innerHTML += ("Peer found. Connecting to " + peerInfo.displayName + "<br />");
    Windows.Networking.Proximity.PeerFinder.connectAsync(peerInfo).done(
        function (socket) {
            id("messageDiv").innerHTML += "Connection successful. You may now send messages.<br />";
            sendMessage(socket);
        },
        function (err) {
            id("messageDiv").innerHTML += "Connection failed: " + err + "<br />";
        });

    requestingPeer = null;
}

function stopFindingPeers() {
    Windows.Networking.Proximity.PeerFinder.stop();
    started = false;
    if (proximitySocket != null) { closeSocket(); }
}

// Handle external connection requests.
var requestingPeer;

function connectionRequested(e) {
    id("messageDiv").innerHTML +=
        "Connection requested by " + e.peerInformation.DisplayName + ". " +
        "Click 'Accept Connection' to connect.";
    requestingPeer = e.PeerInformation;
}

function acceptConnection() {
    if (requestingPeer == null) {
        id("messageDiv").innerHTML += "No peer connection has been requested.";
        return;
    }

    connectToPeer(requestingPeer);
}


Anforderungen

Mindestens unterstützter Client

Windows 8 [Nur Windows Store-Apps]

Mindestens unterstützter Server

Windows Server 2012 [Nur Windows Store-Apps]

Mindestens unterstütztes Telefon

Windows Phone 8

Namespace

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

Metadaten

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]
ID_CAP_NETWORKING [Windows Phone]

Siehe auch

Nähe und Tippen (JavaScript)
Nähe und Tippen (C#/VB/C++)
Beispiele
Nähebeispiel

 

 

Anzeigen:
© 2015 Microsoft