2
I have a question in the behavior of the chunk of a code that is creating a socket server, follows the server code:
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 enter anything... the.hasNextLine() input method should not return false thus ending the while and closing the socket? why this does not happen and the code is "forever" waiting to receive messages typed by the client?
humm this means that if nothing has been typed by the client the hasnextline() method does not return nor true nor false , he stands at this point awaiting some input?
– Mateus Guilherme
@Mateusguilherme I edited my reply adding information.
– StatelessDev