Browse Source

Username Implementation for ClientHandler

remotes/origin/server
Paul Kattenborn 11 months ago
parent
commit
5f094aef56
  1. 6
      src/main/java/ClientHandler.java
  2. 6
      user.json

6
src/main/java/ClientHandler.java

@ -1,6 +1,8 @@
import java.io.*; import java.io.*;
import java.net.Socket; import java.net.Socket;
import javax.swing.JOptionPane;
public class ClientHandler implements Runnable { public class ClientHandler implements Runnable {
private ChatServer chatServer; private ChatServer chatServer;
private Socket connectionToClient; private Socket connectionToClient;
@ -12,7 +14,7 @@ public class ClientHandler implements Runnable {
public ClientHandler(ChatServer chatServer, Socket connectionToClient) { public ClientHandler(ChatServer chatServer, Socket connectionToClient) {
this.chatServer = chatServer; this.chatServer = chatServer;
this.connectionToClient = connectionToClient; 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 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.println(message); // Send the message to the client
toClientWriter.flush(); // Flush the stream toClientWriter.flush(); // Flush the stream
} }
}
}

6
user.json

@ -10,5 +10,11 @@
"userName": "asd1", "userName": "asd1",
"password": "123456", "password": "123456",
"birthday": "1" "birthday": "1"
},
{
"id": "228bf4df-c730-4cd9-9d1c-2446607066aa",
"userName": "jo",
"password": "sieben",
"birthday": "jo"
} }
] ]
Loading…
Cancel
Save