I have the code below in my server, and when I run it, it will read the input from my client only once and then break out of the try block, and ultimately end the while(true) loop.
public void run() {
while (true) {
try {
inputStreamReader = new InputStreamReader(clientSocket.getInputStream());
bufferedReader = new BufferedReader(inputStreamReader);
message = bufferedReader.readLine();
System.out.println("this is message from client: " + message);
} catch (Exception e) {
//nope
}
//end of while
break;
}
}
I want it such that my try block does not finish and that it should always be listening for any incoming messages. If I take the break statement out of the while loop, then I encounter an infinite loop where my message = null. What am I doing wrong?