WinJS.log(message, tag, type):
This helper function can make sending different types of messages to different div boxes easy.
initializeProximityDevice()
This function checks to see if there is already a proximity device assigned in the code. If there is no proximity device assigned, it will get the system default NFC device. If there is no device available, an error will be reported.
triggeredConnectionStateChangedEventHandler(e)
This function lets you handle what happens when the connection state changes.
connectionRequestedEventHandler()
The connectionRequestedEventHandler function lets you designate what happens when another NFC-enabled device tries to request a connection from you.
peerFinder_AcceptRequest()
This function lets the connection complete if the user clicks the Accept Connection button. The function also reports the status to the user.
socketError(errMessage)
This helper function lets you set the output location for error messages.
startReader(dataReader)
This function reads the entire message coming through the dataReader and then writes it out to the user receiving the message.
peerFinder_StartFindingPeers()
Sets the peerFinderStarted flag and then starts the PeerFinder function in the ProxNS library. The function will find all peers asynchronously and populate the drop-down <select> box when complete.
startSendReceive(proximitySocket)
This function starts the process for sending and receiving messages by creating the dataWriter that is to be used in the startReader(dataReader) function. StartSendReceive() also sets both the input and output stream of the socket.
peerFinderConnect()
This function lets you define what happens once a connection is made between peers.
peerFinder_Send()
This function grabs the string in the <Text area> box and then uses the dataWriter to write the message to the socket.
Basic Lifecycle
An application starts by doing a check of the available devices and what types of connections are allowed by that device. If the device / connection types are available, the event handlers are set accordingly. The application flow is controlled by enabling / disabling buttons. If no connection can be made, the send message button will not appear. NFC-capable devices must first advertise themselves by attempting to signal others. When the “Find Peers” button is clicked, the device looks for other device signals and then populates the drop-down box with all the device names it finds. The user on the device that clicked “Find Peers” can now select which device to connect to and click connect button connect. The other user must accept the connection by clicking the “Accept Connection” button. After the connection is made, both devices are free to send messages to each other.
Source Code:
https://www.mediafire.com/?csc77jnahddq69y