|
@ -9,6 +9,7 @@ public class ClientHandler implements Runnable { |
|
|
private String name; |
|
|
private String name; |
|
|
private BufferedReader fromClientReader; |
|
|
private BufferedReader fromClientReader; |
|
|
private PrintWriter toClientWriter; |
|
|
private PrintWriter toClientWriter; |
|
|
|
|
|
private String lastMessage; |
|
|
|
|
|
|
|
|
// Constructor for ClientHandler |
|
|
// Constructor for ClientHandler |
|
|
public ClientHandler(ChatServer chatServer, Socket connectionToClient) { |
|
|
public ClientHandler(ChatServer chatServer, Socket connectionToClient) { |
|
@ -33,6 +34,7 @@ public class ClientHandler implements Runnable { |
|
|
while (message!=null) { |
|
|
while (message!=null) { |
|
|
// Broadcast the client's message to all connected clients |
|
|
// Broadcast the client's message to all connected clients |
|
|
chatServer.broadcastMessage(name + ": " + message); |
|
|
chatServer.broadcastMessage(name + ": " + message); |
|
|
|
|
|
lastMessage = message; |
|
|
message = fromClientReader.readLine(); |
|
|
message = fromClientReader.readLine(); |
|
|
} |
|
|
} |
|
|
} |
|
|
} |
|
@ -64,4 +66,7 @@ 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 |
|
|
} |
|
|
} |
|
|
|
|
|
public String getLastMessage() { |
|
|
|
|
|
return lastMessage; |
|
|
|
|
|
} |
|
|
} |
|
|
} |