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?;
|
||||
|
||||
println!("Connected to server at {}", addr);
|
||||
let mut input = String::new();
|
||||
loop {
|
||||
let mut input = String::new();
|
||||
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
|
||||
println!("Sent message from {}: {}", username.trim(), input.trim());
|
||||
input.clear();
|
||||
println!("Sent message from {}: {}", username.trim(), trimmed_input);
|
||||
}
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user