Added Alexandrs "Tried implementing logout handling (changes only on Server side) " commit

This commit is contained in:
Seraina 2022-03-27 14:49:53 +02:00
parent 0e39f06f9e
commit 4a5bc49aa7
2 changed files with 6 additions and 1 deletions

View File

@ -22,7 +22,6 @@ public class Client {
this.out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
this.in = new BufferedReader((new InputStreamReader((socket.getInputStream()))));
String randomUserName = NameGenerator.randomName();
//TODO hide connecting logik(next 4 lines)
this.userName = userName;
this.out.write(getUsername());

View File

@ -26,6 +26,12 @@ public class Server {
Thread th = new Thread(nextClient);
connectedClients.add(nextClient);
th.start();
// close socket + remove client if client is disconnected
if (socket.getInputStream().read() == -1) {
System.out.println("client disconnected. closing socket");
socket.close();
connectedClients.remove(nextClient);
}
}
} catch (IOException e) {