Windows.Networking.Proximity 네임스페이스

근거리 내에 있는 디바이스 간의 연결을 지원하는 클래스를 포함합니다.

클래스

ConnectionRequestedEventArgs

ConnectionRequested 이벤트를 사용하여 애플리케이션에 전달되는 속성을 포함합니다.

PeerFinder

탭 제스처를 사용하거나 검색하여 주변 디바이스에서 앱의 다른 인스턴스를 검색하고 피어 앱 간에 소켓 연결을 만들 수 있습니다. Windows 8.1 이상에서 Bluetooth 소켓 연결을 만들려면 Windows.Devices.Bluetooth.Rfcomm을 대신 사용합니다.

PeerInformation

피어를 식별하는 정보를 포함합니다.

PeerWatcher

무선 범위 내에서 피어 앱을 동적으로 검색합니다.

ProximityDevice

근접 디바이스에 메시지를 게시하거나 근접 디바이스의 메시지를 구독할 수 있습니다.

ProximityMessage

구독에서 받은 메시지를 나타냅니다.

TriggeredConnectionStateChangedEventArgs

TriggeredConnectionStateChanged 이벤트가 애플리케이션에 전달하는 속성을 포함합니다.

열거형

PeerDiscoveryTypes

PeerFinder 클래스에서 사용할 수 있는 검색 옵션을 나타냅니다.

PeerRole

여러 피어에 연결된 경우 피어 앱의 역할을 설명합니다.

PeerWatcherStatus

PeerWatcher 개체의 상태 설명합니다.

TriggeredConnectState

피어 애플리케이션에 대한 연결의 현재 상태를 나타냅니다.

대리자

DeviceArrivedEventHandler

DeviceArrived 이벤트를 처리하는 메서드에 대해 설명합니다.

DeviceDepartedEventHandler

DeviceDeparted 이벤트를 처리하는 메서드에 대해 설명합니다.

MessageReceivedHandler

구독된 메시지가 수신되었을 때 발생하는 이벤트를 처리할 메서드에 대해 설명합니다.

MessageTransmittedHandler

게시된 메시지가 전송될 때 발생하는 이벤트를 처리할 메서드에 대해 설명합니다.

예제

이 예제에서는 ProximityDevice 클래스를 사용하여 디바이스가 들어오고 근접을 벗어나는 시기를 결정하는 방법을 보여 줍니다.

Windows.Networking.Proximity.ProximityDevice proximityDevice;

private void InitializeProximityDevice()
{
    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault();

    if (proximityDevice != null) {
        proximityDevice.DeviceArrived += ProximityDeviceArrived;
        proximityDevice.DeviceDeparted += ProximityDeviceDeparted;

        WriteMessageText("Proximity device initialized.\n");
    }
    else
    {
        WriteMessageText("Failed to initialized proximity device.\n");
    }
}

private void ProximityDeviceArrived(Windows.Networking.Proximity.ProximityDevice device)
{
    WriteMessageText("Proximate device arrived. id = " + device.DeviceId + "\n");
}

private void ProximityDeviceDeparted(Windows.Networking.Proximity.ProximityDevice device)
{
    WriteMessageText("Proximate device departed. id = " + device.DeviceId + "\n");
}

// Write a message to MessageBlock on the UI thread.
private Windows.UI.Core.CoreDispatcher messageDispatcher = Window.Current.CoreWindow.Dispatcher;

async private void WriteMessageText(string message, bool overwrite = false)
{
    await messageDispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.Normal,
        () =>
        {
            if (overwrite)
                MessageBlock.Text = message;
            else
                MessageBlock.Text += message;
        });
}
Dim proximityDevice As Windows.Networking.Proximity.ProximityDevice

Private Sub InitializeProximityDevice()

    proximityDevice = Windows.Networking.Proximity.ProximityDevice.GetDefault()

    If proximityDevice IsNot Nothing Then
        AddHandler proximityDevice.DeviceArrived, AddressOf ProximityDeviceArrived
        AddHandler proximityDevice.DeviceDeparted, AddressOf ProximityDeviceDeparted

        WriteMessageText("Proximity device initialized." & vbTab)
    Else
        WriteMessageText("Failed to initialized proximity device." & vbTab)
    End If
End Sub

Private Sub ProximityDeviceArrived(device As Windows.Networking.Proximity.ProximityDevice)
    WriteMessageText("Proximate device arrived. id = " & device.DeviceId & vbTab)
End Sub

Private Sub ProximityDeviceDeparted(device As Windows.Networking.Proximity.ProximityDevice)
    WriteMessageText("Proximate device departed. id = " & device.DeviceId & vbTab)
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

설명

간단한 탭 제스처를 사용하여 근접성을 사용하여 컴퓨터를 연결할 수 있습니다. 두 컴퓨터가 서로 3센티미터에서 4cm 이내로 오거나 함께 탭되면 각 컴퓨터의 운영 체제에서 다른 컴퓨터를 검색합니다. 그런 다음 두 컴퓨터를 연결하여 콘텐츠를 공유하거나 메시지를 게시하고 구독할 수 있습니다. 근접은 Wi-Fi Direct를 통해 피어 디바이스의 검색도 지원합니다.

중요

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

추가 정보