-1

i am creating an application which connects 4 devices. one of them acts as a server and the 3 others as client. the server also acts as a client. it is a card game. i have given it 7 UUIDs. when i created the server, 2 of the 3 clients are able to connect but when the 3rd one joins, the app crashes. here is part of the logcat when the 3rd devices try to connect.

        05-12 15:41:55.453: E/ConnectionService(10793): getConnectedSocket : 503c7432-bc23-11de-8a39-0800200c9a66
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793): IOException in getConnectedSocket
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793): java.io.IOException: Service discovery failed
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:377)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:201)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at net.clc.bt.ConnectionService.getConnectedSocket(ConnectionService.java:191)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at net.clc.bt.ConnectionService.access$5(ConnectionService.java:185)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at net.clc.bt.ConnectionService$1.connect(ConnectionService.java:225)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at net.clc.bt.Connection.connect(Connection.java:191)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at net.dillen.satat.Satat.onActivityResult(Satat.java:308)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.app.Activity.dispatchActivityResult(Activity.java:3835)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.app.ActivityThread.deliverResults(ActivityThread.java:3332)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.app.ActivityThread.handleSendResult(ActivityThread.java:3378)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.app.ActivityThread.access$2700(ActivityThread.java:123)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.app.ActivityThread$H.handleMessage(ActivityThread.java:1900)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.os.Handler.dispatchMessage(Handler.java:99)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.os.Looper.loop(Looper.java:123)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at android.app.ActivityThread.main(ActivityThread.java:4370)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at java.lang.reflect.Method.invokeNative(Native Method)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at java.lang.reflect.Method.invoke(Method.java:521)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:868)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:626)
05-12 15:41:55.463: I/net.clc.bt.ConnectionService(10793):  at dalvik.system.NativeStart.main(Native Method)

minSdkVersion="7" 
device OS = 2.3.3 , 2.3.3, 2.1.1, 2.1.1

the problem does not seem to arise with the OS version.

Lucifer
  • 29,392
  • 25
  • 90
  • 143
Waka
  • 3
  • 1
  • 2

1 Answers1

1

I have no comment on the stack trace that you've provided, but the fact that the problem occurs when you try to add your third peer makes me suspicious that you are bumping into a core Bluetooth limitation. Let me explain.

Bluetooth comm takes place in piconets with 1 master (who sets the timing) and up to 7 slaves. For one device to participate in multiple piconets is tricky and inefficient because it has to jump back and forth between the clock cycles of the different piconets. In my experience, a device can only be a slave in 2 piconets, so it would fail when you try to enter a 3rd piconet (though it should fail more gracefully and informatively then this, of course).

The general solution is to designate one device as the piconet master and all the other devices should only connect to this one device. In practise, I've only tried this on systems that allow much more control then Android (where I can, for example, explicitly control master vs. slave) so I can't say how this will work on Android, but you should start with the rule of the thumb that the device that initiates the connection will be the master.

Or I could be over thinking the whole thing. I'm finding the Bluetooth stacks on Android to be very buggy so you might just have encountered a bug. BTW, I'm assuming that the four phones you tested it on are from more then one manufacturer?

Tom
  • 17,103
  • 8
  • 67
  • 75
  • yes, one of them is HTC and the rest are SE..of course of different models. the system is that the 3 other devices connect to the master. so we connect them to only one bluetooth address. when the user click on "join client", he gets a server list and he selects the device who created the server. so there is only one master and the rest are clients. – Waka May 12 '12 at 15:48
  • Ok, that topology is good, but does the master initiate the connections (e.g. does it do the socket.connect)? If no, then I would suggest you try to make it that way. If yes, and you don't find another explanation for your problem, then you could pursue this further by getting root access so you can run HCITOOL which will allow you to inspect the connection and see which device is master. – Tom May 12 '12 at 18:48
  • Yes. it does do the socket.connect. i will try to use the HCITOOL just as u suggested and will post the feedback.. Thanks Tom – Waka May 13 '12 at 05:26
  • Did you find a solution for your problem? I'm having the same issue... http://stackoverflow.com/questions/16935608/pairing-two-android-devices-to-a-third-device-using-bluetooth – Jean-Paul Manuel Jun 05 '13 at 11:33