Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
220 views
in Technique[技术] by (71.8m points)

Weird behaviour while developing a bluetooth chat in android

I'm developing a Bluetooth chat that allows android devices to receive a Bluetooth connection and make Bluetooth requests to other devices running the same app to make them chat together (only p2p no group chats). Now I have a problem when executing the app on several devices, and through trial and error, I'm having some very weird behavior.

Let's take an example, I connect to a device C from A. I then connect to C from another device B. It can happen that C receives a connection request "from A" where INSTEAD B made the actual request. (It happened for real, and I was executing from 5 devices, it was A MESS).

I'm concerned about using the same UUID that has been hardcoded, in all the instances of the app. So two different devices that accept requests use the same UUID and the clients do so. It happens that sockets from server side are still open (even though I close them properly), and now it happens the client throws an exception when executing BluetoothDevice#connect(); saying java.io.IOException: read failed socket might closed or timed-out, read ret: -1 even though BluetoothDevice#createRfcommSocketToServiceRecord(UUID) is returning a socket and not NULL.

I don't include code because I want not to paste 2k lines of code here, it would be too hard to read, but ask me with a comment if you need so. I need to complete it in 2 days and I'm really desperate, I've been googling for 3 hours finding info for UUIDs but nobody really knows the proper way to operate, plus the android documentation only has very basic examples.

Thank you so much for reading this.

question from:https://stackoverflow.com/questions/66065371/weird-behaviour-while-developing-a-bluetooth-chat-in-android

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)
Waitting for answers

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...