As for me I do follows:
Make another thread, that controls some flag. If flag signals "stop waiting" - i close this connection.
public run() {
while (!someFlag) {
sleep(10); //for example
}
inputStream.close();
}
static public void initRead() {
start(); // starts another thread
inputStream.read();
}
-Rico