locked
StreamSocket connection to Bluetooth Device using MAC address RRS feed

  • Question

  • 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:

    1. Visual Studio 2013 on my Windows 8.1 Enterprise dev. machine.
    2. 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

    Friday, October 18, 2013 3:11 PM

All replies

  • I want to clarify the error that you are receiving? Initially you mention that you get a HRESULT: 0x80072741 and later on you mention that you are getting: "There is no inner exception in the raised Access is denied exception".

    What is the actual exception? Is it 0x80072741 or an access denied?


    Windows Store Developer Solutions #WSDevSol || Want more solutions? See our blog, http://aka.ms/t4vuvz

    Monday, October 21, 2013 6:34 PM
    Moderator
  • Can you try with the Hostname value in "curly" braces?

    i.e: HostName printerHostName = new HostName("{7A:00:0B:D7:0F:47}");


    Windows Store Developer Solutions, follow us on Twitter: @WSDevSol|| Want more solutions? See our blog

    Tuesday, October 22, 2013 6:10 PM
    Moderator
  • The curly braces caused an InvalidArgument exception in the HostName constructor.
    Thursday, October 24, 2013 8:49 AM