I have a question about the behavior of the code that is creating a socket server, follow the code of the server:
public class Server {
public static void main(String args[]){
try {
ServerSocket server = new ServerSocket(3322);
System.out.println("Servidor iniciado na porta 3322");
Socket cliente = server.accept();
System.out.println("Cliente conectado do IP "+cliente.getInetAddress().
getHostAddress());
Scanner entrada = new Scanner(cliente.getInputStream());
while(entrada.hasNextLine()){
System.out.println(entrada.nextLine());
}
entrada.close();
server.close();
} catch (IOException ex) {
Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
}
}
After the client connects to the server and for example does not type anything ... the input.hasNextLine () method should not return false thus closing while and closing the socket ? why does not this happen and the code stays "forever" waiting to receive messages typed by the client?