From 5f094aef5657e53ff0505f0c969598f96aebcef6 Mon Sep 17 00:00:00 2001 From: Paul Kattenborn Date: Thu, 8 Feb 2024 01:53:32 +0100 Subject: [PATCH] Username Implementation for ClientHandler --- src/main/java/ClientHandler.java | 6 ++++-- user.json | 6 ++++++ 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/ClientHandler.java b/src/main/java/ClientHandler.java index fa4b924..d443891 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("welcher Benutzername?"); 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 } -} +} diff --git a/user.json b/user.json index 0201a67..5cbff9f 100644 --- a/user.json +++ b/user.json @@ -10,5 +10,11 @@ "userName": "asd1", "password": "123456", "birthday": "1" + }, + { + "id": "228bf4df-c730-4cd9-9d1c-2446607066aa", + "userName": "jo", + "password": "sieben", + "birthday": "jo" } ] \ No newline at end of file