BufferReader using reaLine() is not terminating when end of message.
Hi folks,
Newby Java here. I have a situation where I am writing a Server Socket Java program where I am accepting connection from a client and the client is sending messages me. I am able to connected to the client and the client successfully send messages to me, but the problem I am running into is that it's not terminating the while loop when I read to the end of the message using a reaLine(). It's like it's hung up or something...
Here is a copy of the code.....
ss = new ServerSocket(6500, 5);
System.out.println("Listenning........waiting for connection from client");
try {
response = ss.accept();
System.out.println("Accepted connection from client");
InputStream in = response.getInputStream();
System.out.println("Input Stream Opened");
BufferedReader br = new BufferedReader(new InputStreamReader(in));
System.out.println("Buffered Stream Opened");
System.out.println("Server received: " + "\n" );
BufferedWriter bw = new BufferedWriter(new FileWriter("testing001.txt"));
String input = br.readLine();
while (input != null) {
bw.write(input);
bw.newLine();
input = br.readLine();
}
br.close();
bw.close();
System.out.println("Done receiving message" + "\n" );
OutputStream out = response.getOutputStream();
BufferedWriter buf = new BufferedWriter(new OutputStreamWriter(out));
buf.write(result);
System.out.println("Server sent: "+result);
buf.flush();
buf.close();
response.close();
ss.close();
}
catch (IOException e) {
System.out.println("Failure accepting connection: " + e);
}
What am I doing wrong that the while loop does not terminate when it reads to end of the message using this "readLine()"?
It does not execute the next statement after the while-loop unless you disconnect the connection from the client.
Help!

