I'm using the class DataInputStream to read from a Socket. I must use the readByte (not readLine) because the input does not necessarily in String format. The problem is I must wait the end of the stream to call a function and I couldn't detect it.
The code:
reader = new DataInputStream(socket.getInputStream());
byte dt;
String cmd = "";
while( (dt = reader.readByte()) >= 0){
cmd += (char)dt;
if( /* end of the stream reached */ ){
processInput(cmd);
}
}
System.out.println("End of the loop");
The problem is I don't know how to write this if. And, the end of the loop is not being reached when the Stream ends, the proof of this is that the phrase "End of the loop" is never being printed, so it is just stuck on the loop