Is it possible to implement a timeout in an inputstream.read() function from a BluetoothSocket in Android?
I've tried using Thread.sleep() but this only pauses my activity.
---Update---
I had an idea, make 2 thread code herereads(t1 & t2) where each thread interrupt other, one of them(t1) do a sleep(5000) then interrupt the other thread(t2), from the other side the other thread(t2) if in read the inputstream detects some character as 0x0D interrupt the other thread(t1), but here is my question, does anybody can help me? because i didn't use interrupt() method of threads, I hope someone can help me, thank you...
---Update---
public void run(){
while(true){
try {
char r;
String respuesta = "";
while (true) {
r = (char) mmInStream.read();
respuesta += r;
if (r == 0x3e) {
break;
}
}
respuesta = respuesta.replaceAll(" ", "");
Log.d("respuesta", respuesta);
rHandler.obtainMessage(MESSAGE_READ, -1, -1, respuesta).sendToTarget();
} catch (IOException readException) {
Log.e("ServicioGeneral", "Error de lectura", readException);
this.interrupt();
connectionLost();
// posibly break();
}
}
}
This is my implementation when something comes in a different Thread, the problem is that the timeout will be reached if i dont get the 0x3e character from de mmInStream.
I supposed that in the second example i must use a notifyAll(), but, when do I have to start the readThread()?
Thank you, @weeman