I have BluetoothSocketone that communicates with a custom device (bi-directional). Simetimes (this happens about 1 time out of 4 when transferring 8 MB of data to pieces of 300 bytes), in the middle of transferring files, Bluetooth stops transmitting data. For approximately 100-200 pieces of data (I do not have an exact value), it OutputStream.write(byte[], int, int)continues to return normally after each call. There are no exceptions. Then after that the call is OutputStream.write(byte[], int, int)blocked.
The code has been tested on an ASE Eee TP101 converter.
I don't have access to the low OutputStream code to see what happens and debug. I assume that the buffer is filling but not flushing. When the buffer is full, it writewill be blocked.
Does anyone have an idea what is going on?
Here is an example code: the private class ConnectedThread extends Thread {closed final BluetoothSocket mmSocket; closed final InputStream mmInStream; closed final OutputStream mmOutStream;
public ConnectedThread(BluetoothSocket socket, String socketType) {
mmSocket = socket;
InputStream tmpIn = null;
OutputStream tmpOut = null;
setName( "BT Connected Thread" );
try {
tmpIn = socket.getInputStream();
tmpOut = socket.getOutputStream();
}
catch (IOException e)
{
Log.e( "BT GetStreams", e.getMessage() );
e.printStackTrace();
}
mmInStream = tmpIn;
mmOutStream = tmpOut;
}
public void run() {
byte[] buffer = new byte[1024];
int bytes;
while (true) {
try {
bytes = mmInStream.read(buffer);
mHandler.obtainMessage( FirmwareHandler.COMMAND_READ, bytes, -1, buffer.clone() ).sendToTarget();
} catch (IOException e)
{
connectionLost();
break;
}
}
}
public void write(byte[] buffer, int size) {
try {
Log.d(this.getClass().getSimpleName(), "Before Write, size = " + size + ", mmOutStream.toString() = " + mmOutStream.toString() + ", mmSocket..toString() = " + mmSocket.toString());
mmOutStream.write(buffer, 0, size);
Log.d(this.getClass().getSimpleName(), "After Write");
mmOutStream.flush();
Log.d(this.getClass().getSimpleName(), "After Flush");
} catch (IOException e)
{
e.printStackTrace();
}
}
public void cancel() {
try {
mmSocket.close();
} catch (IOException e)
{
e.printStackTrace();
}
}
}
EDIT:
As soon as the lock happens, if I turn it off, then turn on the remote separation of Bluetooth, the socket will unlock with the exception of IO. Then, when I try to connect, back to the Bluetooth device, I get Bluetooth java.IOException:Service discovery failed. The only way to return Bluetooth is to restart the tablet.
EDIT # 2:
, - . . , ( , , ), :
09-13 09:34:45.342: E/BT Connection Assert(1864): Service discovery failed
09-13 09:34:45.342: W/System.err(1864): java.io.IOException: Service discovery failed
09-13 09:34:45.342: W/System.err(1864): at android.bluetooth.BluetoothSocket$SdpHelper.doSdp(BluetoothSocket.java:397)
09-13 09:34:45.342: W/System.err(1864): at android.bluetooth.BluetoothSocket.connect(BluetoothSocket.java:207)
09-13 09:34:45.342: W/System.err(1864): at com.brioconcept.hit001.communication.bluetooth.BluetoothService$ConnectThread.run(BluetoothService.java:177)
- .