I am sorry because I can't think of any better title.
I has a server-client program written in java that server send a string that end with new line character \n the client read from socket.getInputStream() if input has next line by using Scanner
on server-side
ServerSocket serverSocket = new ServerSocket(PORT);
Socket socket = serverSocket.accept();
PrintWrite send = new PrintWriter(socket.getOutputStream);
send.print("Server has succeeded to proccess your request \n" + show(ID));
send.flush();
The show(ID) is a function that return a string which already contain next line character in it. on client side
Socket socket = new Socket(HOST,PORT);
Scanner read = new Scanner(socket.getInputStream);
public Boolean ServerResponse(){
System.out.println("please wait");
Boolean result=false;
while(true){
if(read.hasNextLine()){
System.out.println("has next");
String msg = read.nextLine();
System.out.println(msg);
if(msg.contains("succeeded")){
result = true;
}
}else{
System.out.println("finished reading server respone");
return result;
}
}
}
when I tried to run this. "finished reading server respone" is never printed and there is no has next after the last line send by Server is printed which assume that there is no next line character. However the else block is never executed. Strangely when I terminate the Server, it is printed. Can anyone please explain this to me and what I must do that I don't need to terminate the server for that line to be printed?