|
|
@ -7,10 +7,10 @@ import java.util.concurrent.CopyOnWriteArrayList; |
|
|
|
|
|
|
|
public class ChatServer { |
|
|
|
private ServerSocket serverSocket; |
|
|
|
private List<ClientHandler> clients; |
|
|
|
private List<ClientHandler> clients; // Liste, um alle verbundenen Clients zu verwalten |
|
|
|
|
|
|
|
public ChatServer(int port) { |
|
|
|
clients = new CopyOnWriteArrayList<>(); |
|
|
|
clients = new CopyOnWriteArrayList<>(); // Verwende CopyOnWriteArrayList für die Thread-Sicherheit |
|
|
|
|
|
|
|
try { |
|
|
|
serverSocket = new ServerSocket(port); |
|
|
@ -18,9 +18,9 @@ public class ChatServer { |
|
|
|
|
|
|
|
while (true) { |
|
|
|
System.out.println("waiting for new Client..."); |
|
|
|
Socket connectionToClient = serverSocket.accept(); |
|
|
|
Socket connectionToClient = serverSocket.accept(); // Auf Verbindungen von Clients warten |
|
|
|
ClientHandler client = new ClientHandler(this, connectionToClient); |
|
|
|
clients.add(client); |
|
|
|
clients.add(client); // Neuen Client zur Liste hinzufügen |
|
|
|
System.out.println("Accepted new Client"); |
|
|
|
} |
|
|
|
} catch (IOException e) { |
|
|
|