I have the following code on the server side:
InputStream in = socket.getInputStream();
int x;
while(true) {
x = in.read();
if(x < 0) break;
System.out.print((char)x);
}
The client is properly connected and sends some string to the server. But the while loop runs forever. How to detect when the end of the input stream is reached.