Tried implementing logout handling (changes only on Server side)

This commit is contained in:
Alexander Sazonov 2022-03-27 03:03:53 +02:00
parent 10bbcdf69e
commit d1b2474702
2 changed files with 8 additions and 1 deletions

View File

@ -102,7 +102,8 @@ public class Client {
public void closeEverything(Socket socket, BufferedReader in, BufferedWriter out) {
//TODO Correctly closing a clients connection
//TODO the server should be notified in a way so he can handle it cleanly
// Is this not already correct?
try {
if (in != null) {
in.close();

View File

@ -27,6 +27,12 @@ public class Server {
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) {
e.printStackTrace();