我有一个Android应用程序向蓝牙打印机发送数据。第一次打印时一切正常,但在第一次打印出错后
错误:
IOException : read failed socket might closed or timeout read
这是我的打印机代码:
BluetoothAdapter mBluetoothAdapter = BluetoothAdapter
.getDefaultAdapter();
BluetoothDevice secilenYazici = mBluetoothAdapter
.getRemoteDevice(sharedPrefs.getString("PRINTER_MAC", ""));
BluetoothSocket socket = secilenYazici
.createRfcommSocketToServiceRecord(MY_UUID);
mBluetoothAdapter.cancelDiscovery();
socket.connect();// exception throwing from this line after first pring.
OutputStream stream = socket.getOutputStream();
// getting printable raw block from webview source.
String[] rawBlocks = lastHTML.split("<!--RawPrint");
String rawEnd = rawBlocks[1].split("-->")[0];
byte[] byteArray = rawEnd.getBytes();
stream.write(byteArray);
stream.close();
socket.close();
我认为关闭后连接会丢失,但是这个代码已经创建了套接字,所以我想我必须关闭它。
答案 0 :(得分:0)