Is there a simple way to turn the standard code:
in = new InputStreamReader(socket.getInputStream());
String message = "";
while ((size = in.read(buf)) != -1){
message += new String(buf, 0, size);
}
so that read()
won't block. I tried doing:
if (!in.ready())
//throw exception
but this throws an exception all the time. Maybe:
socket.setSoTimeout(120000);
in = new InputStreamReader(socket.getInputStream());
but this, as stated by everyone below, doesn't work. Other ideas?