Compare commits
2 Commits
8ff5112352
...
520db4fe58
Author | SHA1 | Date | |
---|---|---|---|
|
520db4fe58 | ||
|
bdecb76824 |
16
src/main.rs
16
src/main.rs
@ -101,14 +101,20 @@ async fn start_client(addr: &str) -> Result<(), Box<dyn Error>> {
|
|||||||
stream.write_all(username.trim().as_bytes()).await?;
|
stream.write_all(username.trim().as_bytes()).await?;
|
||||||
|
|
||||||
println!("Connected to server at {}", addr);
|
println!("Connected to server at {}", addr);
|
||||||
let mut input = String::new();
|
|
||||||
loop {
|
loop {
|
||||||
|
let mut input = String::new();
|
||||||
reader.read_line(&mut input).await?;
|
reader.read_line(&mut input).await?;
|
||||||
stream.write_all(input.trim().as_bytes()).await?;
|
|
||||||
|
let trimmed_input = input.trim();
|
||||||
|
|
||||||
|
if trimmed_input.is_empty() {
|
||||||
|
println!("Empty message. Please enter a non-empty message.");
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
|
||||||
|
stream.write_all(trimmed_input.as_bytes()).await?;
|
||||||
|
|
||||||
// Print sent message
|
// Print sent message
|
||||||
println!("Sent message from {}: {}", username.trim(), input.trim());
|
println!("Sent message from {}: {}", username.trim(), trimmed_input);
|
||||||
input.clear();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user