Compare commits

...

3 Commits

Author SHA1 Message Date
sandwich
d033c4c2c3 Update 'README.md' 2023-07-08 13:36:51 +02:00
Norbert Morawski
520db4fe58 disallow empty messeges 2023-07-08 06:03:34 +02:00
Norbert Morawski
bdecb76824 remove unessesery line 2023-07-08 05:54:56 +02:00
2 changed files with 16 additions and 6 deletions

View File

@@ -1,3 +1,7 @@
# rumes # rumes
A TCP based P2P mesenging CLI Application A TCP based P2P mesenging CLI Application
> its not P2P yet but i am working on it.
Don't take this Project seriously, i am just using it to learn TCP sockets and the Tokio librery

View File

@@ -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();
} }
} }