Windows 8 Metro Study Notes (16)-NFC

Source: Internet
Author: User
NFC(Near Field commuciation), short-range wireless communication technology, is a short-range high-frequency wireless communication technology. What is the difference between Bluetooth and Bluetooth?
I found the differences on the Internet:
(1) transmission distance
The NFC transmission distance is generally 10 cm, while the Bluetooth transmission distance can reach 10 meters.
(2) Configuration
You do not need to manually set matching for NFC. You only need to touch the two devices. Bluetooth needs to be set and matched separately.
(3) applicable scenarios
NFC is applicable in many scenarios, such as payment, logging, and Card swiping. Bluetooth is applicable in a limited range of scenarios.

Winrt API corresponding to NFC --Windows. Networking. Proximity
Peerfinder
This class can be used to discover nearby devices, create socket connections with them, and send receiving information. Peerfinder. triggeredconnectionstatechanged + = new typedeventhandler <object, triggeredconnectionstatechangedeventargs> (triggeredconnectionstatechangedeventhandler );
Peerfinder. connectionrequested + = new typedeventhandler <object, connectionrequestedeventargs> (peerconnectionrequested );

Peerfinder. Start ();
Ireadonlylist <peerinformation> _ peerinformationlist = await peerfinder. findallpeersasync ();
Streamsocket _ socket = await peerfinder. connectasync (peertoconnect );

First, register two events:
Triggeredconnectionstatechanged: used to track a connection status during touch with a remote machine
Connectionrequested: triggered when the remote machine has a connection request
Call the corresponding method:
Findallpeersasync (): browse all computers that run the same app in the wireless area
Await peerfinder. connectasync (): connected to the same computer in the range

 

ProximitydeviceYou can send or subscribe to a message to a device, that is, send a message, and then touch another device to receive the corresponding message.
Event:
Devicearrived: triggered when a device enters within a close range.
Devicedeparted: triggered when a device is removed within a close range.

 

// Instantiate a proximitydevice object and activate it
Proximitydevice _ proximitydevice = proximitydevice. getdefault ();
// Send a message. Of course, the sending method has many reloads. You can send characters, binary streams, and Uris.
Long _ publishedmessageid = _ proximitydevice. publishmessage ("windows. samplemessagetype", publishtext );

 

// Run the subscribe Method on another device to obtain the message long _ subscribedmessageid = _ proximitydevice. subscribeformessage ("windows. samplemessagetype", messagereceived );
Void messagereceived (proximitydevice, proximitymessage message)
{
If (message. messagetype = "stringmessage ")
{
String MEs = message. dataasstring;
}
Else if (message. messagetype = "buffermessage ")
{
Ibuffer buffer = message. Data;
}
}

Of course there are other attributes and Methods. Here we will not try them one by one. It is quite fun to do a complete demo process and test it. Peerfind: to use this object, you need to first find, connect, and then transmit information.
Proximitydevice: This method is relatively simple. One End sends a message, and the other end only needs to subscribe to obtain the message, provided that the distance is quite close.

 

If you have a deeper understanding of this technology, I hope you can give some advice ~

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.