locked
Client FindAllAsync() Can't Find by Service over BT/RFComm

    Question

  • Hi,

    Just starting development for Windows Store Apps. Need to connect Windows 8.1 Tablet (Client) to Windows 8.1 PC (Device). On the PC, I am running a simple Blank App that defines an RFComm serviceID in its manifest: Here's the Device/Service code:

            async void InitializeAsync()
            {
                _provider = await RfcommServiceProvider.CreateAsync(RfcommServiceId.FromUuid(RfcommServiceUuid));
          
                _listener = new StreamSocketListener();
                _listener.ConnectionReceived += listener_ConnectionReceived;
          
                await _listener.BindServiceNameAsync(_provider.ServiceId.AsString(), SocketProtectionLevel.BluetoothEncryptionAllowNullAuthentication);
         
                var writer = new DataWriter();
                writer.WriteByte(SERVICE_VERSION_ATTRIBUTE_TYPE);
                writer.WriteUInt32(SERVICE_VERSION);
         
                var data = writer.DetachBuffer();
                _provider.SdpRawAttributes.Add(SERVICE_VERSION_ATTRIBUTE_ID, data);
                _provider.StartAdvertising(_listener);
    
                listActivity.Items.Add("Listening for connections...");
            }
    
            void listener_ConnectionReceived(StreamSocketListener sender, StreamSocketListenerConnectionReceivedEventArgs args)
            {
                listActivity.Items.Add("Connection received");
                listActivity.Items.Add("Stopped listening");
    
                // Stop advertising/listening so that we’re only serving one client
                _provider.StopAdvertising();
    
                _listener.Dispose();
                _listener = null;
    
                _socket = args.Socket;
                _reader = new DataReader(this._socket.InputStream);
                this.Run();
            

    Here's the code for the Tablet Client-side:

    private async Task<bool> SetupDeviceConn()
            {
                string deviceSelector = RfcommDeviceService.GetDeviceSelector(RfcommServiceId.FromUuid(RfcommServiceUuid));           
                var services = await Windows.Devices.Enumeration.DeviceInformation.FindAllAsync(deviceSelector);
                if (services.Count > 0)
                {
                    // Initialize the target Bluetooth BR device
                    var service = await RfcommDeviceService.FromIdAsync(services[0].Id);
    

    Examining deviceSelector string shows that the BT/RFComm service id is included; however FindAllAsync() always returns services.Count = 0

    Any assistance is appreciated.

    Thursday, July 17, 2014 6:01 PM

All replies

  • Hi fadish,

    Did you pair two devices before you running the code?

    As I know Windows Store App does not provide pair function since it belong to a system level, and you may need to pair the devices manually.

    --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.

    Friday, July 18, 2014 5:59 AM
    Moderator
  • Thanks for the response, James

    Yes, the two devices are paired; just want to prove out the ability to connect. I basically followed the RFComm Scenarios presented here and here. I also tried changing the RFCommService type to SerialPort and ObjectPush, etc. (on both client and server) with the same results: FindAllAsync returns zero services.

    Thanks

    Friday, July 18, 2014 12:41 PM