Using Bluetooth Rfcomm in Windows 8.1 RRS feed

  • Question

  • Hello,

    I'm trying to create a connection between two universal apps. But i cant make them find each other.

    Client side:

    	txtOutput.Text += "\nConnect() - Starting";
                txtOutput.Text += "\nConnect() - starting searching for devices running this app...";
                deviceServiceInfoCollection = await DeviceInformation.FindAllAsync(
                txtOutput.Text += "\nConnect() - ended searching for devices running this app";
                txtOutput.Text += "\nConnect() - starting processing list";
                if (deviceServiceInfoCollection.Count > 0)
                    foreach (var device in deviceServiceInfoCollection)
                        txtOutput.Text += "\nConnect() - processing " + device.Name;
                        if (device.Name.Equals("MYPC"))
                            txtOutput.Text += "\nConnect() - MYPC found!";

    From which im getting this output (even when i take my BL dongle off!! no errors!!):

    Connect() - Starting
    Connect() - starting searching for devices running this app...
    Connect() - ended searching for devices running this app
    Connect() - starting processing list

    Server side:

    private const uint ServiceVersionAttributeId = 0x0300;
            private const byte ServiceVersionAttributeType = 0x0A;
            private const uint ServiceVersion = 200;


    txtOutput.Text += "\nStartListen() - Starting"; provider = await RfcommServiceProvider.CreateAsync( RfcommServiceId.FromUuid(RfcommServiceUuid)); txtOutput.Text += "\nStartListen() - provider received."; StreamSocketListener listener = new StreamSocketListener(); listener.ConnectionReceived += HandleConnectionReceived; txtOutput.Text += "\nStartListen() - listener received."; await listener.BindServiceNameAsync( provider.ServiceId.AsString(), SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication); txtOutput.Text += "\nStartListen() - bindServiceNameAsync."; var writer = new DataWriter(); txtOutput.Text += "\nStartListen() - dataWriter created."; writer.WriteByte(ServiceVersionAttributeType); writer.WriteUInt32(ServiceVersion); txtOutput.Text += "\nStartListen() - service version defined."; var data = writer.DetachBuffer(); provider.SdpRawAttributes.Add(ServiceVersionAttributeId, data); provider.StartAdvertising(listener); txtOutput.Text += "\nStartListen() - started advertising.";


            private void HandleConnectionReceived(StreamSocketListener listener, StreamSocketListenerConnectionReceivedEventArgs args)
                txtOutput.Text += "\nHandleConnectionReceived() - Starting";
                listener = null;
                txtOutput.Text += "\nHandleConnectionReceived() - stopped advertising.";
                this.socket = args.Socket;
                this.dataReader = new DataReader(this.socket.InputStream);
    private void Run()
                txtOutput.Text += "\nRun() - Starting";
                while (true)
                        txtOutput.Text += "\nRun() - starting reading";
                        uint stringLength = dataReader.UnconsumedBufferLength;
                        String message = (String)this.dataReader.ReadString(stringLength);
                        txtOutput.Text += "\nRun() - message read";
                    catch (Exception)

    From which i get (this time, when i disconnect the BL dongle, it wont run - which seems good):

    StartListen() - Starting
    StartListen() - provider received.
    StartListen() - listener received.
    StartListen() - bindServiceNameAsync.
    StartListen() - dataWriter created.
    StartListen() - service version defined.
    StartListen() - started advertising.

    (adapted from this example: http://www.silverlightshow.net/items/Windows-8.1-Play-with-Bluetooth-Rfcomm.aspx)

    Also, in both manifests:

         <Capability Name="privateNetworkClientServer" />
         <Capability Name="internetClientServer" />
         <m2:DeviceCapability Name="bluetooth.rfcomm">
           <m2:Device Id="any">
              <m2:Function Type="serviceId:(THE SAME ID BOTH WAYS)" />

    I also tried in client:

    PeerFinder.AlternateIdentities["Bluetooth:PAIRED"] = "";
            var devices = await PeerFinder.FindAllPeersAsync();
            var device = devices.FirstOrDefault();
    But it just gets stuck (with or without my BL dongle on), wont even get to the device line.

    So what am i doing wrong? Can someone help please?

    Thank you in advance!

    • Edited by nevespf Friday, December 26, 2014 4:25 PM
    Friday, December 26, 2014 3:55 PM

All replies

  • Hi,

    If you trying connect two Universal apps through Bluetooth, can you check if the Windows 8.1 Bluetooth RFComm sample runs fine on both the devices? I successfully tested the Windows 8.1 Bluetooth RFComm sample on Laptop (Windows 8.1) and Windows Phone 8.1 (paired).

    Make sure the service which you are trying to advertise/listen is supported by both the devices. 


    Friday, December 26, 2014 4:48 PM
  • I tried that sample and it did not work. Please remember that i am trying to connect Win8.1PC-Win8.1PC.

    It says it found no paired device advertising the service. But they are paired.

    Friday, December 26, 2014 5:10 PM
  • Before the samples run on both the devices, are they paired and connected through Bluetooth? You can check this by going to Bluetooth settings.


    Friday, December 26, 2014 5:57 PM
  • They are paired. I even tried sending a file through windows between them to test it, and it worked.
    Saturday, December 27, 2014 11:40 AM
  • Could this be because the PeerFinder and Rfcomm classes have different behaviors in W8.1 and WP?
    Saturday, January 3, 2015 11:35 AM