With some quick fixes it will sort of work:
- In the server, in
envoyerMessage
, add a newline at the end of the message:printer.write(message + "\n");
The client is reading from the server usingclientReader.readLine
, and so it would be stuck until it receives a newline. - In the client, in
main
, fix the string comparison to use...equals("fin")
instead of!=
, otherwise no matter what you enter, thewhile
loop will never end.
As you are working on this, I recommend to work on the server first and use telnet
as your client:
telnet localhost 9999
After the basic stuff works, try things like:
- Connect 2-3 times in a row: can the server handle that correctly?
- Connect from 2-3 windows at the same time: can the server handle concurrent clients? (Ok this might be beyond your scope...)
After the server works well, work on the client (to replace telnet).