This post is about proximity devices and scenarios enabled by using this functionality.
WinRT supports Near Field Communication (NFC) scenarios by providing native support using Windows.Networking.Proximity namespace. This namespace enable working with proximity device in two different modes – direct communication using sockets (ProximityStreamSocket class) and publish/subscribe mode (using ProximityMessage class). ProximityDevice class provides gateway to hardware NFC device component (if present in computer/tablet, drivers are installed and user permits using such type of devices).
To use Proximity device it must be manifested in Capabilities section of application manifest:
In both cases first you need to acquire the proximity device:
Using sockets requires using PeerFinder class which helps looking for devices, enables getting requests from arriving device and connection to them. Once two peers completer the connection cycle (PeerFinder.TriggeredConnectionState == TriggeredConnectState.Completed) event arguments provides an instance of ProximitryStreamSocket class which is used to transmit data between devices.
While this technique is relatively advanced and requires subscribing to multiple events and managing socketed connection, ProximityDevice class provides easier way to transmit messages between two PCs/Tablets. Using pub/sub model requires subscribing to known message type from one hand and publishing known message type from other hand. Once connection established and message delivered devices can stop publishing/listening to the messages:
In addition, ProximityDevice enables subscribing to DeviceArrived and DeviceDeparted events, which helps to maintain state of connected/disconnected devices and provides information about them:
Note: MessageType parameter in PublishMessage function must begin from “Windows.”
That’s it for now.
Stay tuned for next part.