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

ぃ、小莉子 提交于 2019-12-10 13:09:19

问题


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.


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




回答2:


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.



来源:https://stackoverflow.com/questions/9834203/can-you-establish-multiple-bluetooth-connections-between-the-same-two-devices-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!