I am using the Android Bluetooth Chat Sample, and I was wondering how and
where I should add codes to able to connect to multiple devices?
On Wednesday, December 22, 2010 8:57:53 PM UTC-6, Kristopher Micinski wrote:
>
> Many people have this problem, this implements a Bluetooth Piconet,
> this is why this is using seven different UUIDs for the Bluetooth
> socket.
> I went through this example and saw how it is implemented, it is
> similar to how we implement this client/server functionality in a few
> of our applications in our research.
> I believe the key to getting this to work is inthe mUuid list.
>
> Take a close look at what this is doing?
>
> for (int i = 0; i < Connection.MAX_SUPPORTED && myBSock ==
> null; i++) {
> for (int j = 0; j < 3 && myBSock == null; j++) {
> myBSock = getConnectedSocket(myBtServer, mUuid.get(i));
> if (myBSock == null) {
> try {
> Thread.sleep(200);
> } catch (InterruptedException e) {
> Log.e(TAG, "InterruptedException in connect",
> e);
> }
> }
> }
> }
>
> What this code does is looks to connect to the device, but how does it
> do so? It tries the socket multiple times, using multiple UUIDs for
> the session. In essence it means that we can use UUID only *once*. So
> instead this application implements using seven UUIDs, then the server
> listens and accepts each UUID on the server side, this is what is done
> with the following code:
>
> for (int i = 0; i < Connection.MAX_SUPPORTED &&
> maxConnections > 0; i++) {
> BluetoothServerSocket myServerSocket = mBtAdapter
>
> .listenUsingRfcommWithServiceRecord(srcApp, mUuid.get(i));
> BluetoothSocket myBSock = myServerSocket.accept();
> myServerSocket.close(); // Close the socket now that
> the
> // connection has been made.
>
> String address =
> myBSock.getRemoteDevice().getAddress();
>
> mBtSockets.put(address, myBSock);
> mBtDeviceAddresses.add(address);
> Thread mBtStreamWatcherThread = new Thread(new
> BtStreamWatcher(address));
> mBtStreamWatcherThread.start();
> mBtStreamWatcherThreads.put(address,
> mBtStreamWatcherThread);
> maxConnections = maxConnections - 1;
> if (mCallback != null) {
> mCallback.incomingConnection(address);
> }
> }
>
> Now, on the client side of things what is done? The client does not
> know how many active connections the server currently has. If we have
> some agreed upon order that the clients must use we can simply use
> this, however, in our case, we simply just try *each UUID* in sequence
> until we "find the right one."
>
> Hopefully this helps you, and everyone else who has questions about
> this problem, feel free to email me with problems you have.
>
> Short version:
> -- Use multiple UUIDs, you can only use one at once. So define seven
> (max for piconet usage) and try each one until you find the right one.
>
> Thanks,
> Kristopher Micinski
> Michigan State University
>
> 2010/12/22 苗鹏 <[email protected]>
> >
> > I looked at the FBTClickLinkCompete'source,
> > for (int i = 0; i < Connection.MAX_SUPPORTED && myBSock == null; i++) {
> > for (int j = 0; j < 3 && myBSock == null; j++) {
> > myBSock = getConnectedSocket(myBtServer,
> mUuid.get(i));
> > if (myBSock == null) {
> > try {
> > Thread.sleep(200);
> > } catch (InterruptedException e) {
> > Log.e(TAG, "InterruptedException in
> connect", e);
> > }
> > }
> > }
> > }
> > This code fragment shows a client that trys to connect the server...
> The sample of SDK(BluetoothChat) used same code except
> > for (int i = 0; i < Connection.MAX_SUPPORTED && myBSock == null; i++) {
> > for (int j = 0; j < 3 && myBSock == null; j++) { ....
> > I don't understand why? what'more, it can't connect to multiple
> devices at the same time!
> > Thanks!!!
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> >
> > 2010/12/21 Morrison Chang <[email protected]>
> >>
> >> Look at http://code.google.com/p/apps-for-android/
> >> Specifically the code for BTClickLinkCompete for a sample of Bluetooth
> >> connectivity.
> >>
> http://code.google.com/p/apps-for-android/source/browse/#svn%2Ftrunk%2FBTClickLinkCompete
> >>
> >> I think the air hockey sample supports 4 other devices along with the
> >> server device.
> >>
> >> -Morrison
> >>
> >> On Dec 20, 3:37 am, 苗鹏 <[email protected]> wrote:
> >> > could you share me your code?Thanks!
> >> >
> >> > 2010/12/20 James <[email protected]>
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> >
> >> > > of course you can,
> >> >
> >> > > On Dec 18, 9:25 am, 苗鹏 <[email protected]> wrote:
> >> > > > It is possible to connect simultaneously to multiple bluetooth
> devices?
> >> >
> >> > > --
> >> > > You received this message because you are subscribed to the Google
> >> > > Groups "Android Developers" group.
> >> > > To post to this group, send email to
> [email protected]
> >> > > To unsubscribe from this group, send email to
> >> > > [email protected]<android-developers%2Bunsubs
> >> > >
> [email protected]>
> >> > > For more options, visit this group at
> >> > >http://groups.google.com/group/android-developers?hl=en
> >>
> >> --
> >> You received this message because you are subscribed to the Google
> >> Groups "Android Developers" group.
> >> To post to this group, send email to
> [email protected]
> >> To unsubscribe from this group, send email to
> >> [email protected]
> >> For more options, visit this group at
> >> http://groups.google.com/group/android-developers?hl=en
> >
> > --
> > You received this message because you are subscribed to the Google
> > Groups "Android Developers" group.
> > To post to this group, send email to [email protected]
> > To unsubscribe from this group, send email to
> > [email protected]
> > For more options, visit this group at
> > http://groups.google.com/group/android-developers?hl=en
>
>
--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en