このページは役に立ちましたか。
このページのコンテンツについての ご意見をお待ちしております
その他にご意見はありますか。
残り 1500 文字
エクスポート (0) 印刷
すべて展開
情報
要求されたトピックは次のとおりです。しかし、このトピックはこのライブラリには含まれていません。

TriggeredConnectionStateChangedEventArgs Class

アプリケーションに渡す TriggeredConnectionStateChanged イベントのプロパティを含みます。

構文


Public NotInheritable Class TriggeredConnectionStateChangedEventArgs

属性

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

メンバー

TriggeredConnectionStateChangedEventArgsクラス には次の種類のメンバーがあります。

メソッド

The TriggeredConnectionStateChangedEventArgs クラス からメソッドを継承します。Object クラス (C#/VB/C++).

プロパティ

TriggeredConnectionStateChangedEventArgsクラス には次のプロパティがあります。

プロパティアクセスの種類説明

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

名前空間

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

メタデータ

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

参照

TriggeredConnectionStateChanged
近接通信とタップ (JavaScript)
近接通信とタップ (C#/VB/C++)
サンプル
近接通信のサンプル

 

 

表示:
© 2015 Microsoft