MSDN Library
Information
The topic you requested is included in another documentation set. For convenience, it's displayed below. Choose Switch to see the topic in its original location.

TriggeredConnectionStateChangedEventArgs class

Contains properties that the TriggeredConnectionStateChanged event passes to an application.

Syntax


Public NotInheritable Class TriggeredConnectionStateChangedEventArgs

Members

The TriggeredConnectionStateChangedEventArgs class has these types of members:

Methods

The TriggeredConnectionStateChangedEventArgs class inherits methods from the Object class (C#/VB/C++).

Properties

The TriggeredConnectionStateChangedEventArgs class has these properties.

PropertyAccess typeDescription

Id

Read-onlyGets the unique identifier for the connection in progress.

Socket

Read-onlyGets the StreamSocket instance for the connection.

State

Read-onlyGets the state of the connection in progress.

 

Examples


' 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


Requirements (Windows 10 device family)

Device family

Universal, introduced version 10.0.10240.0

API contract

Windows.Foundation.UniversalApiContract, introduced version 1.0

Namespace

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

Metadata

Windows.Foundation.UniversalApiContract.winmd

Capabilities

proximity

Requirements (Windows 8.x and Windows Phone 8.x)

Minimum supported client

Windows 8 [Windows Store apps only]

Minimum supported server

Windows Server 2012 [Windows Store apps only]

Minimum supported phone

Windows Phone 8

Namespace

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

Metadata

Windows.winmd

Capabilities

proximity
ID_CAP_PROXIMITY [Windows Phone]

Attributes

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

See also

Object
TriggeredConnectionStateChanged
Proximity and Tapping (JavaScript)
Proximity and Tapping (C#/VB/C++)
Samples
Proximity sample

 

 

Show:
© 2016 Microsoft