diff --git a/.classpath b/.classpath index 8d95b91..acc4f10 100644 --- a/.classpath +++ b/.classpath @@ -1,40 +1,41 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/java/ChatServer.java b/src/main/java/ChatServer.java index 0c60774..f43051b 100644 --- a/src/main/java/ChatServer.java +++ b/src/main/java/ChatServer.java @@ -39,10 +39,10 @@ public class ChatServer { } // Methode, um eine Nachricht an alle verbundenen Clients zu senden public void broadcastMessage(String message) { - System.out.println(message); - if (message != null) { - for (ClientHandler client : clients) { - client.sendMessage(message); // Nachricht an jeden Client senden + System.out.println(message); + if (message != null) { + for (ClientHandler client : clients) { + client.sendMessage(message); } } @@ -56,5 +56,8 @@ public class ChatServer { public void removeClient(ClientHandler client) { clients.remove(client); } + public List getClients() { + return clients; + } } \ No newline at end of file diff --git a/src/main/java/ClientHandler.java b/src/main/java/ClientHandler.java index 74fa305..e4104da 100644 --- a/src/main/java/ClientHandler.java +++ b/src/main/java/ClientHandler.java @@ -1,6 +1,8 @@ import java.io.*; import java.net.Socket; +import javax.swing.JOptionPane; + public class ClientHandler implements Runnable { private ChatServer chatServer; private Socket connectionToClient; @@ -12,7 +14,7 @@ public class ClientHandler implements Runnable { public ClientHandler(ChatServer chatServer, Socket connectionToClient) { this.chatServer = chatServer; this.connectionToClient = connectionToClient; - name = connectionToClient.getInetAddress().getHostAddress(); // Use the client's IP address as their name for simplicity + name = JOptionPane.showInputDialog("Benutzername für neuen Client vergeben"); new Thread(this).start();} // Start a new thread for this client handler @@ -62,4 +64,4 @@ public class ClientHandler implements Runnable { toClientWriter.println(message); // Send the message to the client toClientWriter.flush(); // Flush the stream } -} +}