TriggeredConnectionStateChangedEventArgs Class

TriggeredConnectionStateChanged 이벤트가 응용 프로그램에 전달하는 속성을 포함합니다.

구문


/* 이 개체를 만들거나 액세스하는 방법에 대한 자세한 내용은 설명을 참조하십시오. */

특성

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

멤버

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

메서드

The TriggeredConnectionStateChangedEventArgs 클래스 - 다음에서 메서드를 상속합니다. Object 클래스 (C#/VB/C++).

속성

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

속성사용 권한Description

Id

읽기 전용Gets the unique identifier for the connection in progress.

Socket

읽기 전용Gets the StreamSocket instance for the connection.

State

읽기 전용Gets the state of the connection in progress.

 

예제


function id(elementId) {
    return document.getElementById(elementId);
}

// Click event for "Start" button.
function startFindingPeers() {
    if (Windows.Networking.Proximity.PeerFinder.supportedDiscoveryTypes &
        Windows.Networking.Proximity.PeerDiscoveryTypes.triggered) {

        Windows.Networking.Proximity.PeerFinder.start();

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

        id("messageDiv").innerHTML += 
    "Waiting for peers. Enter proximity to connect. " +
    "Call PeerFinder.start() on the peer to send and receive messages.<br />";
    }
    else {
        id("messageDiv").innerHTML += 
    "Peer discovery using tapping is not supported.<br />";
    }

}

function triggeredConnectionStateChanged(e) {
    if (e.state === Windows.Networking.Proximity.TriggeredConnectState.completed) {
        id("messageDiv").innerHTML += "Connected. You may now send a message.<br />";
        sendMessage(e.socket);
    }
}

var proximitySocket;
var dataWriter;

// Reference socket streams for writing and reading messages.
function sendMessage(socket) {
    id("sendMessageButton").addEventListener("click", sendMessageText);

    // Get the network socket from the proximity connection.
    proximitySocket = socket;

    // Create DataWriter for writing messages to peers.
    dataWriter = new Windows.Storage.Streams.DataWriter(proximitySocket.outputStream);
            
    // Listen for messages from peers.
    var dataReader = new Windows.Storage.Streams.DataReader(proximitySocket.inputStream);
    startReader(proximitySocket, dataReader);
}

// Send a message to the socket.
function sendMessageText() {        
    var msg = id("sendMessageText").value;
    
    if (msg.length > 0) {
        var msgLength = dataWriter.measureString(msg);
        dataWriter.writeInt32(msgLength);
        dataWriter.writeString(msg);
        dataWriter.storeAsync().done(
            function (byteCount) {
                id("messageDiv").innerHTML += "Message sent: " + msg.value + "<br />";
            },
            function (err) {
                id("messageDiv").innerHTML += "Send error: " + err.message + "<br />";
            });
    }
}

// Read out and print the message received from the socket.
function startReader(socket, reader) {
    var initialLength = 4; 
    reader.loadAsync(initialLength).done(
    function () {
        var msgLength = reader.readInt32();
        reader.loadAsync(msgLength).done(
            function () {
                var message = reader.readString(msgLength);
                id("messageDiv").innerHTML += "Received message: " + message + "<br />";

                // After receiving a message, listen for the next message.
                startReader(socket, reader);
            },
            function (err) {
                id("messageDiv").innerHTML += "Error: " + err.message + "<br />";
                socket.close();
            });
    },
    function (err) {
        id("messageDiv").innerHTML += "Error: " + err.message + "<br />";
        socket.close();
    });
}


요구 사항

지원되는 최소 클라이언트

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]

참고 항목

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

 

 

표시:
© 2014 Microsoft