0

I have scanner(on client) that is getting information from(server), when server sends all required strings, all the code after that is just not being executed(like it paused execution of the program). Example(it loops and prints good, until server is sending all the data, but, when its finished, it does not execute print, or any other command, even in the loop itself!):

while(scanner1.hasNextLine()){
     System.out.print("-- " + scanner1.nextLine());
}
 System.out.print("Something bla bla");

RESULT: -- data 1 -- data 2

Btw, i am new in Java, so if I made any stupid mistakes, I apologize :)

Luka
  • 3
  • 2

1 Answers1

1

The program is waiting for the remote to either send an end of line marker (e.g. '\n'), or close its socket output stream. However it seems like the server doesn't send any of them. So instead of using Scanner here you should try using something like client.getInputStream().read()

dammina
  • 655
  • 1
  • 8
  • 23
  • If on server we can close the socket by doing socket.close(); , how should we start it again? I am useing printwriter: PrintWriter out = new PrintWriter(clientConnection.getOutputStream(), true); – Luka Nov 11 '16 at 20:52