Can you establish multiple Bluetooth connections between the same two devices in Android?
Asked Answered
K

2

6

I have two Android devices. One is acting as a server and the other as a client. The client connects to the server and requests a file - this is done in one thread on the client and one thread on the server so that both can continue doing what they want.

The client then attempts to connect to the server again to request another file. Right now I am getting a java.io.IOException: Device or resource busy when attempting to connect (socket.connect()). Is it because Bluetooth (on Android) only allows one channel between two devices? (if it were another device it would work but if it is the same it doesn't ?) Note that both attempts are made with the same service name and UUID.

Even if the error is specific to my code, I would like to know if this is the case or not.

System: android 2.2.1 communicating with the bluecove bluetooth library.

Krys answered 23/3, 2012 at 4:33 Comment(0)
P
1

AFAIK, multiple connectivity is not possible in case of Bluetooth Connection. Bluetooth is Connectivity API is by default Synchronized so only one connection at a time is possible. So you can not perform multiple connections.

However it can be possible in another way like making one connection , performing 2 seconds operation on it and then creating another connection and performing 2 seconds operations like in normal multitasking operating system happens.

Polygenesis answered 23/3, 2012 at 4:40 Comment(1)
Then can you explain, for example, how can a laptop connect via bluetooth to a keyboard a mouse and a headset at the same time?Blackandblue
K
6

Definitely not with the same UUID(universally UNIQUE Identifier).

Reference for that was taken from here

Maybe with more than one. You can connect multiple devices in the Server/Client style, you can try to set one of the devices as a server and start several clients on the other. My first guess would be to start several client threads, but you might have to find a way to change the MAC address for each of them.

Here you can find another discussion about how to change your mac address, but only works in rooted devices. I can't find anything else for non rooted ones. No idea on how to do this programmatically but it might give you a start.

Here there is a discussion about connecting several clients at the same time in a server. I got there from this question. ( I think this might be your closest shot)

Here you have a discussion about peer-to-peer networks.

Kentiggerma answered 14/11, 2012 at 15:15 Comment(5)
I have been able to establish multiple parallel connections, by unregistering the SDP on current channel and registering it again on a new free channel once the current channel has been allocated as a result of 'connect' from the device. UUID has been same. The problem arises when 4-5 simultaneous client threads are trying to connect.Runnels
I'm out of ideas for that. As you managed to use the same UUID you should be able to open 7 client connections. When you get the busy error do all the threads stop working or just your latest client can't join the net?Kentiggerma
only the latest client can't join, btw is there something special with 7?Runnels
I'm not an expert in Bluetooth but A Piconet is limited to 7 slaves. They have 3 bit addresses so, 2^3=8 and 1 is the master. You can read more here en.wikipedia.org/wiki/Scatternet. I'll fiddle around with the bluetooth api and see if I can find something else.Kentiggerma
@Runnels How do you unregister the SDP of the current channel?Incompetent
P
1

AFAIK, multiple connectivity is not possible in case of Bluetooth Connection. Bluetooth is Connectivity API is by default Synchronized so only one connection at a time is possible. So you can not perform multiple connections.

However it can be possible in another way like making one connection , performing 2 seconds operation on it and then creating another connection and performing 2 seconds operations like in normal multitasking operating system happens.

Polygenesis answered 23/3, 2012 at 4:40 Comment(1)
Then can you explain, for example, how can a laptop connect via bluetooth to a keyboard a mouse and a headset at the same time?Blackandblue

© 2022 - 2024 — McMap. All rights reserved.