Added Alexandrs "Tried implementing logout handling (changes only on Server side) " commit
This commit is contained in:
parent
0e39f06f9e
commit
4a5bc49aa7
@ -22,7 +22,6 @@ public class Client {
|
|||||||
this.out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
this.out = new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()));
|
||||||
this.in = new BufferedReader((new InputStreamReader((socket.getInputStream()))));
|
this.in = new BufferedReader((new InputStreamReader((socket.getInputStream()))));
|
||||||
|
|
||||||
String randomUserName = NameGenerator.randomName();
|
|
||||||
//TODO hide connecting logik(next 4 lines)
|
//TODO hide connecting logik(next 4 lines)
|
||||||
this.userName = userName;
|
this.userName = userName;
|
||||||
this.out.write(getUsername());
|
this.out.write(getUsername());
|
||||||
|
|||||||
@ -26,6 +26,12 @@ public class Server {
|
|||||||
Thread th = new Thread(nextClient);
|
Thread th = new Thread(nextClient);
|
||||||
connectedClients.add(nextClient);
|
connectedClients.add(nextClient);
|
||||||
th.start();
|
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) {
|
} catch (IOException e) {
|
||||||
|
|||||||
Reference in New Issue
Block a user