I'm trying to discover devices on a peer-to-peer basis using the PeerFinder
class of the Windows Phone 8 Proximity
API.
I'm running the app in Visual Studio 2013 using the Windows Phone 8 emulator. I use the PeerFinder
class like this:
PeerFinder.AllowInfrastructure = true;
PeerFinder.Start();
After this, I attempt to discover other peers like this:
while (true)
{
try
{
var result = await PeerFinder.FindAllPeersAsync();
if (result.Count > 0)
System.Diagnostics.Debug.WriteLine("FOUND A PEER!");
}
catch (Exception ex)
System.Diagnostics.Debug.WriteLine("encountered error!!!");
}
The error I get on the line with FindAllPeersAsync() is the following:
An exception of type 'System.Exception' occurred in mscorlib.ni.dll but was not handled in user code
Additional information: The device is not connected. (Exception from HRESULT: 0x8007048F)
I thought the problem might be the fact that it is running within an emulator and not on an actual device. Is networking like this (peer-to-peer with or without infrastructure) possible in the emulator, or am I forgetting something?
Any help would be much appreciated. Thanks!
As is said on this page: "The Windows Phone Emulator does not have any built-in support for testing Proximity, requiring you test your NFC functionality using a Windows Phone 8 that supports NFC." and "Bluetooth cannot be tested using Windows Phone Emulator."
I'd suggest to test your code on actual device, otherwise you might not be able to to debug your app properly.
Proximity for Windows Phone 8
http://msdn.microsoft.com/en-us/library/windowsphone/develop/jj207060(v=vs.105).aspx
For PeerFinder browse mode where the user picks a nearby device from a list (eg FindAllPeersAsync) it is not supported to use the emulator.
However, the "triggered" mode (eg which uses TriggeredConnectionStateChanged) which uses NFC where users tap two devices together back to back instead of selecting from a list, is actually supported in the emulator though you'll need an external tool to make it work available here: http://proximitytapper.codeplex.com/
You just need to launch two different emulators (the emulators must be different resolutions to be able to run at the same time) and in the tool multi-select both of the emulators (which should pop in in the list) and click tap to simulate as if they were tapped back-to-back with NFC.
User contributions licensed under CC BY-SA 3.0