software you can take with you

Listening to incoming connection on Windows Mobile

Last post 02-15-2009 2:33 PM by alanjmcf. 4 replies.
Page 1 of 1 (5 items)
Sort Posts: Previous Next
  • 02-09-2009 5:33 AM

    Listening to incoming connection on Windows Mobile

    Hi,

    I've a hardware device which tries to connect to the next nearby mobile device. Once it found a device it looks for a specific service and starts sending data. Unfortunately I don't know exactly how the client device is working. I know it searches for a service name and starts the pairing process. When the right pairing code is entered it starts sending data via SPP. The only feedback I have are some error codes shown on a display.

    My solution was to create a service record with a specific name and pass this to a BluetoothListener as shown below.

                ServiceRecordBuilder bldr = new ServiceRecordBuilder();
                bldr.AddServiceClass(BluetoothService.SerialPort);
                bldr.ServiceName = "MyServiceName";

                bl = new BluetoothListener(service, bldr.ServiceRecord);
                bl.Start();

                BluetoothClient bc = bl.AcceptBluetoothClient();

    The hardware device starts a pairing process and according to the error code I know it found my service. After I've entered the pairing code I'm waiting for the incoming connection to accept. But the problem is that the method AcceptBluetoothClient() never returns.

    Did I miss something in my BluetoothListener configuration? Or should I use virtual COM ports instead?

    I've a Java demo which works properly with the hardware device:

              String url = "btspp://localhost:00112233445566778899AABBCCDDEEFF;name=MyServiceName";
    notifier = (StreamConnectionNotifier)Connector.open(url);

    // block the current thread until a client responds
    con = notifier.acceptAndOpen();

    The method acceptAndOpen() returns after I've entered the pairing code and the device connects to my mobile device.

  • 02-09-2009 11:09 AM In reply to

    • B.J.YU
    • Top 100 Contributor
    • Joined on 12-29-2008
    • Republic Of Korea
    • Posts 10

    Re: Listening to incoming connection on Windows Mobile

    oops,, i'm sorry. i wrote a wrong reply.

    but i don't know how to this post delete.

  • 02-09-2009 11:18 AM In reply to

    Re: Listening to incoming connection on Windows Mobile

    If that Java sample really works then I think you need something like:

       ServiceRecordBuilder bldr = new ServiceRecordBuilder();
       Guid svcClass = new Guid("00112233445566778899AABBCCDDEEFF");
       bldr.AddServiceClass(svcClass);
       bldr.ServiceName = "MyServiceName";

       bl = new BluetoothListener(service, bldr.ServiceRecord);
       bl.Start();

       BluetoothClient bc = bl.AcceptBluetoothClient();

    That seems a funny UUID however... :-,)

  • 02-09-2009 12:11 PM In reply to

    Re: Listening to incoming connection on Windows Mobile

    The Java sample is not exactly the same :). It's using a unique GUID but I thought that's not important.

    What is definetively working is that the client device can find my custom service. I think it is enumerating all services on my mobile device and selects the device with the name "MyServiceName" and ignores the GUID.

    The "funny" thing is that sometimes the device can establish a connection. That means AcceptBluetoothclient() returns and I can read the incoming stream. But this happens randomly and I've no clue what could be the reason for this.

    I'm not a Bluetooth specialist although I've learned a lot in the last few days :). Right now I'm doing trial and error using different parameters. Is it possible that I have to configure a specific RFCOMM channel?

  • 02-15-2009 2:33 PM In reply to

    Re: Listening to incoming connection on Windows Mobile

    Don't know whether you've got this working well now.  My only suggestion was to run the SdpBrowserXxxx sample and look at the SDP record published by the two apps (Java vs .NET) and see if there are any differences in them.

Page 1 of 1 (5 items)
Copyright © 2001-2013 In The Hand Ltd. All rights reserved. Terms of Use and Privacy Policy. OrcsWeb's Windows Cloud Server Hosting