andrey-ushakov / flutter_bluetooth_basic

Flutter plugin. Allows to find bluetooth devices & send raw bytes data
BSD 3-Clause "New" or "Revised" License
40 stars 134 forks source link

java.io.IOException: read failed, socket might closed or timeout, read ret: -1 #8

Open devblopper opened 4 years ago

devblopper commented 4 years ago

After some uses of a bluetooth printer, i often get this exception fired up and the printer stops working:

W/System.err( 1964): java.io.IOException: read failed, socket might closed or timeout, read ret: -1 W/System.err( 1964): at android.bluetooth.BluetoothSocket.readAll(BluetoothSocket.java:762) W/System.err( 1964): at android.bluetooth.BluetoothSocket.readInt(BluetoothSocket.java:776) W/System.err( 1964): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:399) W/System.err( 1964): at com.gprinter.io.BluetoothPort.openPort(BluetoothPort.java:58) W/System.err( 1964): at com.tablemi.flutter_bluetooth_basic.DeviceConnFactoryManager.openPort(DeviceConnFactoryManager.java:156) W/System.err( 1964): at com.tablemi.flutter_bluetooth_basic.FlutterBluetoothBasicPlugin$3.run(FlutterBluetoothBasicPlugin.java:233) W/System.err( 1964): at com.tablemi.flutter_bluetooth_basic.ThreadPool$1.run(ThreadPool.java:78) W/System.err( 1964): at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1167) W/System.err( 1964): at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:641) W/System.err( 1964): at java.lang.Thread.run(Thread.java:764)

Seems related to this: https://stackoverflow.com/questions/18657427/ioexception-read-failed-socket-might-closed-bluetooth-on-android-4-3?rq=1

Unfortunately this code is not directly accessible as it is found on the library gprintersdkv2.jar, so i can´t fast check if the proposed solution fix the error. I found early versions of the library, but those are incompatible with the current calls on DeviceConnFactoryManager.java, so a reimplementation of some sort is required. The libary could be decompiled but i don´t know if its license allow that.

I´m using esc_pos_bluetooth also, and my printer is MUNBYN

deep34 commented 3 years ago

Did you manage to solve the issue ? I have the same problem.

invweb commented 6 months ago

@devblopper @deep34 -> I have the same problem, did you manage to solve it? share the solution.