locked
build win 8.1 bluetooth app server

    Question

  • at resent days , I'm studying how to build a app that communication via Bluetooth on the win8.1 pcs , one app use to be a server ,

    the other is as to be a client , the server use Bluetooth rfcomm service provider to provide a Bluetooth service ,

    the client use the

           rfcomm.RfcommDeviceService.getDeviceSelector(rfcomm.RfcommServiceId.obexObjectPush)).done(

    function(services) {

     to find the service that provided on the Bluetooth server , I also add the

    Capability both the server an the client like this :

    <

    Capabilities>

        <

    CapabilityName="internetClientServer"/>

        <

    CapabilityName="privateNetworkClientServer"/>

        <

    m2:DeviceCapabilityName="bluetooth.rfcomm">

          <

    m2:DeviceId="any">

            <

    m2:FunctionType="name:obexObjectPush"/>

          </

    m2:Device>

        </

    m2:DeviceCapability>

      </

    Capabilities>

     buut the client couldn't find the service , can you show me some sample about that ? or where is the problem ? does it need some another setting ?

    I just study it for a little days , so please help me to resolve this issue ?

    how to use the win8.1   Bluetooth app  client to find the win8.1   Bluetooth app server  service   ?

    please help me , thanks very much !

    or show me some setting about them , or some sample ,

    please give me a guide  , thanks very much !!!

    Monday, November 17, 2014 1:20 PM

Answers

All replies

  • my win8.1 pc Bluetooth app couldn't find the win8.1 Bluetooth server service :

    the server code :

     

    functionInitialize()

        {

       


            Windows.Devices.Bluetooth.Rfcomm.RfcommServiceProvider.createAsync(

                rfcomm.RfcommServiceId.obexObjectPush).done(

    function(provider) {

                    _provider = provider;

                   

    // Create a listener for this service and start listening


                    _listener =

    newWindows.Networking.Sockets.StreamSocketListener();

                    _listener.addEventListener(

                       

    "connectionreceived", OnConnectionReceived);

              

    return      _listener.bindServiceNameAsync(

                       _provider.serviceId.asString(),

                       Windows.Networking.Sockets.SocketProtectionLevel.bluetoothEncryptionAllowNullAuthentication);

                      

                });

           

    // Set the SDP attributes and start advertising


           

    //.bluetoothEncryptionAllowNullAuthentication   .plainSocket


                InitializeServiceSdpAttributes(_provider);

                _provider.startAdvertising(_listener);

                WinJS.log && WinJS.log(

    "server start ", "sample", "status");

           

        }

       

    functionInitializeServiceSdpAttributes(provider)

            {

                  writer =

    newWindows.Storage.Streams.DataWriter();

               

    // First write the attribute type


                writer.writeByte(SERVICE_VERSION_ATTRIBUTE_TYPE)

               

    // Then write the data


                writer.writeUInt32(SERVICE_VERSION);

       

               

    vardata = writer.detachBuffer();

                provider.sdpRawAttributes.insert(SERVICE_VERSION_ATTRIBUTE_ID, data);

             

            }

       <

    CapabilityName="privateNetworkClientServer"/>

        <

    CapabilityName="internetClientServer"/>

        <

    m2:DeviceCapabilityName="bluetooth.rfcomm">

              <

    m2:DeviceId="any">

                <

    m2:FunctionType="name:obexObjectPush"/>

          </

    m2:Device>

        </

    m2:DeviceCapability>

    client code :

      Windows.Devices.Enumeration.DeviceInformation.findAllAsync(

           rfcomm.RfcommDeviceService.getDeviceSelector(rfcomm.RfcommServiceId.obexObjectPush),null).done(

    function(services) {

                   

    if(services.length > 0) {

                        chatServices = services;

                       

    while(serviceList.firstChild) {

                            serviceList.removeChild(serviceList.firstChild);

                        }

                       

    for(vari = 0; i < services.length; i++) {

                           

    varservice = services[i];

          

    varserviceName = document.createElement("option");

                        serviceName.innerText = service.name;

                        serviceList.appendChild(serviceName);

                   

                        }

                        serviceList.selectedIndex = -1;

                        serviceSelector.style.display =

    "";

                    }

    else{

                        WinJS.log && WinJS.log(

    "No chat services were found. Please pair Windows with a device that is "+

                           

    "advertising the chat service", "sample", "status");

                    }

                });

    <

    CapabilityName="internetClientServer"/>

        <

    CapabilityName="privateNetworkClientServer"/>

        <

    m2:DeviceCapabilityName="bluetooth.rfcomm">

          <

    m2:DeviceId="any">

            <

    m2:FunctionType="name:obexObjectPush"/>

          </

    m2:Device>

        </

    m2:DeviceCapability>

    I wrote the codes like that , I also paired the two pcs by Bluetooth , but the client couldn't find the

    server service , the services length also "  0 " , could you help me about this issue ?

    does the app need another settings , thanks very much !!!

     I'm troubled about this for a long time , can you give me some advise ?

    or a sample that could work via the bluetooth .

    thanks very much !!!

     

    Monday, November 17, 2014 12:27 PM
  • varSERVICE_VERSION_ATTRIBUTE_ID = 0x0300;

       

    varSERVICE_VERSION_ATTRIBUTE_TYPE = 0x0A;   // UINT32


       

    varSERVICE_VERSION = 200;

    Monday, November 17, 2014 12:28 PM
  •  i have two win8.1 pcs , one is to be a bluetooth app server user rfcomm serviceprovider API to provide a Bluetooth service ,

    the other one is a Bluetooth app client use

    RfcommDeviceService.getDeviceSelector(rfcomm.RfcommServiceId.fromUuid(RFCOMM_CHAT_SERVICE_UUID)),

    null).done(function(services) {

    to find a Bluetooth service ,

    I also set Capabilities like this for the server and the client :

      <

    Capabilities>

        <

    CapabilityName="internetClientServer"/>

        <

    CapabilityName="privateNetworkClientServer"/>

        <

    m2:DeviceCapabilityName="bluetooth.rfcomm">

          <

    m2:DeviceId="any">

            <

    m2:FunctionType="name:obexObjectPush"/>

          </

    m2:Device>

        </

    m2:DeviceCapability>

      </

    Capabilities>

    but my Bluetooth client couldn't find the Bluetooth server service , does is need another setting for the two pcs ?

    or can you show me some samples about win8.1 communicate over the Bluetooth ?

    or how to provide a Bluetooth service let the client app could find ?

    thanks very much !!!

    Monday, November 17, 2014 1:03 PM
  • Hi RainGuy,

    Here is a sample: https://code.msdn.microsoft.com/windowsapps/Bluetooth-Rfcomm-Chat-afcee559

    You could see how they communicate with each other and how they play as one device and one server.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Tuesday, November 18, 2014 6:37 AM
    Moderator
  • hi James ,

    thanks for your help , I run the javascript client on my win8.1 ,

    also I run the c# chat server on win8.1 , and paired the bluetooth  and set the Capabilities ,

    but the client couldn't find the c# server service , do you know what's the reason ?

    does I need other pc settings or bluetooth settings  to let the client find the server service ?

    Tuesday, November 18, 2014 9:14 AM
  • No you don't need to if you pair the device, that is the only thing you need to do, but double check if you have enable the Bluetooth on both device and pair them correctly.

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.



    Tuesday, November 18, 2014 9:15 AM
    Moderator
  • hi Jamles ,

    could you enumerate some points about  building the communication over the bluetooth rfcomm on win8.1 PCs ,

    that could make the client find the server service correctly . or guide me some ideas about

     the conditions  on the win8.1 pc to  build  bluetooth rfcomm app  , and let the apps communicate over the bluetooth correctly !

    could you show me a sample that you have run on your visual studio ?

    thanks very much , now I'm worried about it very much !!!

    Tuesday, November 18, 2014 12:18 PM
  • Please ref to another thread I replied: https://social.msdn.microsoft.com/Forums/windowsapps/en-US/bdfce970-3ac8-4481-8e8f-fef01bda727b/win81-bluetooth-server-service-the-difference-abput-paired-the-bluetooth-between-before-starting?forum=winappswithhtml5#c20af513-db4c-4bcf-9cc4-e10da6f21bb5

    --James


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Wednesday, November 26, 2014 9:53 AM
    Moderator