Hi,
I am trying to connect to a Bluetooth printer from my Windows 8.1 Store app as follows:
using Windows.Networking.Sockets;
StreamSocket streamSocket = new StreamSocket();
HostName printerHostName = new HostName("7A:00:0B:D7:0F:47");
await streamSocket.ConnectAsync(printerHostName, "BtPrinter", SocketProtectionLevel.PlainSocket);
The ConnectAsync function throws this exception:
The requested address is not valid in its context. (Exception from HRESULT: 0x80072741)
I work with the following environment:
-
Visual Studio 2013 on my Windows 8.1 Enterprise dev. machine.
-
Windows 8.1 (less than enterprise) on my Acer Iconia tablet, with remote debugger.
I checked the following things:
-
Bluetooth is enabled in the tablet, it is able to discover bluetooth devices.
-
There is no inner exception in the raised Access is denied exception.
-
I enabled all capabilities in the apps manifest.
-
I have tried all values of the SocketProtectionLevel enum, all values produce the same exception.
-
I made sure the app is allowed to communicate through the windows firewall (no idea if that is related to my problem, I hope it doesn't harm)
I added the following capability xml to the manifest file:
<m2:DeviceCapability Name="bluetooth.rfcomm">
<m2:Device Id="any">
<m2:Function Type="name:serialPort"/>
</m2:Device>
</m2:DeviceCapability>
Still I am unable to connect the StreamSocket! I have no idea why? I hop I didn't miss anything. Your help is appreciated, thanks in advance.
Regards,
Faris