flutter_bluetooth_serial
flutter_bluetooth_serial copied to clipboard
read failed, socket might closed or timeout, read ret: -1
Tried to use the package to add chat feature ,always getting this error when try to connect to a paired device (android mobile) as below .
read failed, socket might closed or timeout, read ret: -1
What I tried:
- Remote device(android smart phone) already paired and isn't busy.
- UUID is The same"00001101-0000-1000-8000-00805F9B34FB", tried to generate random one or get the remote device's still not working .
- Tried to test it with deferent types of android mobiles(galaxy and oppo) amd still the same .
I'm stucked at this point ,really need to implement this feature asap , soo any help ??
Thanks in advanced,
Hi @HajerWael. Were you able to solve this error?
Same here, in my case i'm tying to connect to an Intel NUC.
Hi @martesabt. What's the occurance rate of this error for you? Is it random or you are stuck with it?
Hey @vaibhiarora03, unfortunately I'm stuck with it.
I also tried to connect the device to the Intel NUC through BT system settings, and it worked. Then when I request BT devices with the package the Intel NUC has the status connected.
Hi @martesabt .
I did some searching for this issue and had implemented it from those learnings. You can have a look at my implementation. Though the code I tried didn't work for me but worked for many others. Maybe it can help you out. https://stackoverflow.com/questions/71038323/ioexception-read-failed-socket-might-closed-or-timeout-read-ret-1
My source:- https://stackoverflow.com/questions/18657427/ioexception-read-failed-socket-might-closed-bluetooth-on-android-4-3
Thanks @vaibhiarora03 I will take a look at it.
I noticed you closed #160 did you found an alternative?
This is frustrating :(
@martesabt The logs which i mentioned in the post had my custom logs in it making it useless to point to the exact issue. Thats why closed it and opened a new issue with proper information.
#164
@vaibhiarora03 Oh, ok!
I hope we can solve this!
hello Everyone I have read failed, socket might be closed or timeout read ret: -1 this issues you all are using static UUID for the connection so that you are facing this issue, You can use your Bluetooth device UUID for the connection and you can resolve this issue.
You can change BluetoothConnection.java class you can replace connect method
/// Connects to given device by hardware address (default UUID used) public void connect(String address) throws IOException { BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice device = btAdapter.getRemoteDevice(address); ParcelUuid[] uuids = (ParcelUuid[]) device.getUuids(); connect(address, uuids[0].getUuid()); }
hello Everyone I have read failed, socket might be closed or timeout read ret: -1 this issues you all are using static UUID for the connection so that you are facing this issue, You can use your Bluetooth device UUID for the connection and you can resolve this issue.
You can change BluetoothConnection.java class you can replace connect method
/// Connects to given device by hardware address (default UUID used) public void connect(String address) throws IOException { BluetoothAdapter btAdapter = BluetoothAdapter.getDefaultAdapter(); BluetoothDevice device = btAdapter.getRemoteDevice(address); ParcelUuid[] uuids = (ParcelUuid[]) device.getUuids(); connect(address, uuids[0].getUuid()); }
this saved me, thx man
@RRohitM I tried this method, but it caused my code to compile to my device. Were there any other changes that you made to the base example codes?
I tried @RRohitM solution but still same issue
This should help. https://stackoverflow.com/a/25647197/5552022
So change from
device.createRfcommSocketToServiceRecord(uuid); // or device.createInsecureRfcommSocketToServiceRecord(uuid);
to
socket = (BluetoothSocket) device.getClass().getMethod("createRfcommSocket", new Class[] {int.class}).invoke(device, 1);