Answered by:
proximity sockets: trying to understand how it works.

Question
-
hello guys.
I've started looking at the proximity code, but I must admit that I can only look at it because I don't have nfc in my laptop. Now, the question: the docs mention that you connect two devices with a simple tap or by browsing for devices. the browsing part is easy to understand: you list the items and then pull one and pass it to PeerFinder.connectAsync. In this case, the target will get the connectionRequested event fired and it will be able to get info from the origin peer. Is this correct?
Now, what I'd like to confirm is the behavior associated with tap.
From what I've seen, it looks like I need to call PeerFinder.start to put the app in "listening mode". Then, from within the function that handles the triggerconnectionstatechanged event, I need to get the proximity socket when the state is set to completed:
function handleChange(e) {
if( e.state === Windows.Networking.Proximity.TriggeredConnectState.peerFound){
socket = e.socket;//get proximity socket
}
}btw, I'm also assuming that getting the socket for sending and receiving data is always done within the triggerconnectionstatechanged event in both cases (ie, whether you connect through connectAsync or by tapping). Am I right?
thanks
Luis Abreu
Wednesday, April 18, 2012 5:06 PM
Answers
-
There is an explanation of how you can install a proximity tap simulator on the proximity sample page: http://code.msdn.microsoft.com/windowsapps/Proximity-Sample-88129731#content
What you've described is correct about the TriggeredConnectionStateChanged event and how you get the resulting StreamSocket, though your sample code above is trying to access the socket in the wrong state - peerFound. ConnectAsync is for Browse connections only and is not used for Tap connections. When using ConnectAsync, the socket is returned from the ConnectAsync operation and does not use the TriggeredConnectionStateChanged event. You can see how this is done in the code snippet on the TriggeredConnectionStateChanged event API reference page in the 'connectToPeer' function: http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.proximity.peerfinder.triggeredconnectionstatechanged.aspx
Thanks,
Mike (MSFT)
- Proposed as answer by Mike L [MSFT] Friday, May 4, 2012 10:29 PM
- Marked as answer by Jie Bao Monday, May 7, 2012 10:18 AM
Friday, May 4, 2012 10:26 PM
All replies
-
Given that socket is a property of TriggeredConnectionStateChangedEventArgs, and nowhere else in the Windows.Networking.Proximity class, the answer seems is "yes".
Matt Small - Microsoft Escalation Engineer - Forum Moderator
- Proposed as answer by Matt SmallMicrosoft employee, Moderator Friday, April 20, 2012 3:26 PM
Friday, April 20, 2012 3:26 PMModerator -
Hello Matt.
Without the proper hw, I have no way to test it, so I need to ask...
Luis Abreu
Friday, April 20, 2012 8:01 PM -
You can use wifi-direct to test.
Monday, April 23, 2012 4:40 PM -
I'll give it a try...
Luis Abreu
Monday, April 23, 2012 8:59 PM -
There is an explanation of how you can install a proximity tap simulator on the proximity sample page: http://code.msdn.microsoft.com/windowsapps/Proximity-Sample-88129731#content
What you've described is correct about the TriggeredConnectionStateChanged event and how you get the resulting StreamSocket, though your sample code above is trying to access the socket in the wrong state - peerFound. ConnectAsync is for Browse connections only and is not used for Tap connections. When using ConnectAsync, the socket is returned from the ConnectAsync operation and does not use the TriggeredConnectionStateChanged event. You can see how this is done in the code snippet on the TriggeredConnectionStateChanged event API reference page in the 'connectToPeer' function: http://msdn.microsoft.com/en-us/library/windows/apps/windows.networking.proximity.peerfinder.triggeredconnectionstatechanged.aspx
Thanks,
Mike (MSFT)
- Proposed as answer by Mike L [MSFT] Friday, May 4, 2012 10:29 PM
- Marked as answer by Jie Bao Monday, May 7, 2012 10:18 AM
Friday, May 4, 2012 10:26 PM -
To help install the sample driver that emulates NFC, I wrote an article :
Hope it helps.
Stéphanie
Stéphanie H. Relations Techniques Développeurs - Microsoft
Friday, November 22, 2013 12:50 PM