정보
요청한 주제가 아래에 표시됩니다. 그러나 이 주제는 이 라이브러리에 포함되지 않습니다.

PeerFinder Class

주변 장치에서 응용 프로그램의 다른 인스턴스를 검색하고 누르기 제스처 또는 탐색을 사용하여 피어 응용 프로그램 간에 소켓 연결을 만들 수 있습니다.

구문


var peerFinder = Windows.Networking.Proximity.PeerFinder;

특성

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

멤버

PeerFinder클래스에는 다음과 같은 형식의 멤버가 있습니다.

이벤트

PeerFinder클래스에는 다음과 같은 이벤트가 있습니다.

이벤트Description
ConnectionRequested Occurs when a remote peer requests a connection using the ConnectAsync method.
TriggeredConnectionStateChanged Occurs during a tap gesture from a remote peer.

 

메서드

The PeerFinder 클래스 - 이러한 메서드가 있습니다. C#, Visual Basic 및 C++에서는 다음 위치의 메서드도 상속합니다. Object 클래스.

메서드Description
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.

 

속성

PeerFinder클래스 - 이러한 속성이 있습니다.

속성사용 권한Description

AllowBluetooth

읽기/쓰기Specifies whether the PeerFinder class may connect a StreamSocket object by using Bluetooth.

AllowInfrastructure

읽기/쓰기Specifies whether the PeerFinder class may connect to a StreamSocket object using TCP/IP.

AllowWiFiDirect

읽기/쓰기Specifies whether the PeerFinder class may connect a StreamSocket object by using Wi-Fi Direct.

AlternateIdentities

읽기 전용Gets a list of alternate appId values to match with peer applications on other platforms.

DiscoveryData

읽기/쓰기Gets or sets the name that identifies your computer to remote peers.

DisplayName

읽기/쓰기Gets or sets the name that identifies your computer to remote peers.

Role

읽기/쓰기Gets or sets the role of the app in peer-to-peer connections.

SupportedDiscoveryTypes

읽기 전용Gets a value that indicates which discovery options are available to use with the PeerFinder class.

 

설명

중요   

근접 API는 인증, 암호화 또는 메시지 무결성을 제공하지 않습니다. 근접을 사용하여 암호, 재무 데이터, 텍스트 메시지, 전자 메일, 사진 또는 정부 ID 번호와 같은 중요 사용자 정보를 교환하지 마십시오.

예제


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);
}


요구 사항

지원되는 최소 클라이언트

Windows 8 [Windows 스토어 앱만]

지원되는 최소 서버

Windows Server 2012 [Windows 스토어 앱만]

지원되는 최소 전화

Windows Phone 8

Namespace

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

Metadata

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]
ID_CAP_NETWORKING [Windows Phone]

참고 항목

근접 연결 및 탭(JavaScript)
근접 연결 및 탭(C#/VB/C++)
샘플
근접 연결 샘플

 

 

표시: