dimanche 8 mars 2015

Read Java socket inputstream without thread.sleep() in the below code?


Vote count:

0





public static void waitUntil(String prompt, InputStream instr) {
while (true) {

try {
try {
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (instr.available() >= 5) {
byte[] buff = new byte[1024];
int ret_read = 0;
ret_read = instr.read(buff);
if (ret_read > 0) {
if ((new String(buff, 0, ret_read)).contains(prompt)
&& flag) {
break;
}
}
}
} catch (IOException e) {
e.printStackTrace();
}
}
}


If if remove that thread.sleep(1000) or even i reduce the to less than 1000 its not working properly. Question : How to read java socket inputstream without thread.sleep() till all all incoming bytes are arrived?



asked 48 secs ago







Read Java socket inputstream without thread.sleep() in the below code?

Aucun commentaire:

Enregistrer un commentaire