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

TriggeredConnectionStateChangedEventArgs Class

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

구문


Public NotInheritable Class TriggeredConnectionStateChangedEventArgs

특성

[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.

 

예제


' Click event for "Start" button.

Private Sub StartFindingPeersButton_Click(sender As Object, e As RoutedEventArgs)

    If ((Windows.Networking.Proximity.PeerFinder.SupportedDiscoveryTypes &
         Windows.Networking.Proximity.PeerDiscoveryTypes.Triggered) =
         Windows.Networking.Proximity.PeerDiscoveryTypes.Triggered) Then

        Windows.Networking.Proximity.PeerFinder.Start()

        AddHandler Windows.Networking.Proximity.PeerFinder.TriggeredConnectionStateChanged,
            AddressOf TriggeredConnectionStateChanged

        WriteMessageText("Waiting for peers. Enter proximity to connect. " &
            "Call PeerFinder.start() on the peer to send and receive messages." & vbTab)
    Else
        WriteMessageText("Peer discovery using tapping is not supported." & vbTab)
    End If
End Sub

Private Sub TriggeredConnectionStateChanged(sender As Object,
    e As Windows.Networking.Proximity.TriggeredConnectionStateChangedEventArgs)

    If e.State = Windows.Networking.Proximity.TriggeredConnectState.Completed Then
        WriteMessageText("Connected. You may now send a message." & vbTab)
        SendMessage(e.Socket)
    End If
End Sub

Private proximitySocket As Windows.Networking.Sockets.StreamSocket
Private dataWriter As Windows.Storage.Streams.DataWriter

' Reference socket streams for writing and reading messages.
Private Sub SendMessage(socket As Windows.Networking.Sockets.StreamSocket)
    ' 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.
    Dim dataReader = New Windows.Storage.Streams.DataReader(proximitySocket.InputStream)
    StartReader(proximitySocket, dataReader)
End Sub

' Send a message to the socket.
Private Async Sub SendMessageText()
    Dim msg = SendMessageTextBlock.Text

    If msg.Length > 0 Then
        Dim msgLength = dataWriter.MeasureString(msg)
        dataWriter.WriteInt32(msg.Length)
        dataWriter.WriteString(msg)
        Try
            Await dataWriter.StoreAsync()
            WriteMessageText("Message sent: " & msg & vbTab)
        Catch e As Exception
            WriteMessageText("Send error: " & e.Message & vbTab)
        End Try
    End If
End Sub

' Read out and print the message received from the socket.
Private Async Sub StartReader(
    socket As Windows.Networking.Sockets.StreamSocket,
    reader As Windows.Storage.Streams.DataReader)

    Dim initialLength As UInteger = 4

    Try
        Await reader.LoadAsync(initialLength)
        Dim msgLength = CType(reader.ReadInt32(), UInteger)

        Try
            Await reader.LoadAsync(msgLength)
            Dim message = reader.ReadString(msgLength)
            WriteMessageText("Received message: " & message & vbTab)

            ' After receiving a message, listen for the next message.
            StartReader(socket, reader)
        Catch e As Exception
            WriteMessageText("Error: " & e.Message & vbTab)
            socket.Dispose()
        End Try
    Catch e As Exception
        WriteMessageText("Error: " & e.Message & vbTab)
        socket.Dispose()
    End Try
End Sub

' Write a message to MessageBlock on the UI thread.
Private Async Sub WriteMessageText(message As String, Optional overwrite As Boolean = False)
    Await Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
        Sub()
            If overwrite Then
                MessageBlock.Text = message
            Else
                MessageBlock.Text &= message
            End If
        End Sub)
End Sub


요구 사항

지원되는 최소 클라이언트

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++)
샘플
근접 연결 샘플

 

 

표시: