Add sent messege feedback
This commit is contained in:
parent
4110778123
commit
4110207303
@ -49,7 +49,7 @@ async fn start_server(addr: &str) -> Result<(), Box<dyn Error>> {
|
||||
let clients_shared = Arc::clone(&clients);
|
||||
|
||||
// Insert client into the shared HashMap
|
||||
clients_shared.lock().unwrap().insert(client_addr, username);
|
||||
clients_shared.lock().unwrap().insert(client_addr, username.clone());
|
||||
|
||||
// Spawn a new task for each client connection
|
||||
tokio::spawn(async move {
|
||||
@ -72,11 +72,12 @@ async fn start_server(addr: &str) -> Result<(), Box<dyn Error>> {
|
||||
|
||||
let username = clients_shared.lock().unwrap().get(&client_addr).unwrap_or(&"Unknown".to_string()).clone();
|
||||
|
||||
let message = String::from_utf8_lossy(&buf[..n]).to_string();
|
||||
println!(
|
||||
"Received message from {} ({}): {}",
|
||||
username,
|
||||
client_addr,
|
||||
String::from_utf8_lossy(&buf[..n])
|
||||
message
|
||||
);
|
||||
|
||||
if let Err(e) = socket.write_all(&buf[0..n]).await {
|
||||
@ -104,6 +105,9 @@ async fn start_client(addr: &str) -> Result<(), Box<dyn Error>> {
|
||||
loop {
|
||||
std::io::stdin().read_line(&mut input)?;
|
||||
stream.write_all(input.as_bytes()).await?;
|
||||
|
||||
// Print sent messege
|
||||
println!("Sent message from {}: {}", username.trim(), input.trim());
|
||||
input.clear();
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user