Compare commits
3 Commits
8ff5112352
...
main
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
d033c4c2c3 | ||
|
|
520db4fe58 | ||
|
|
bdecb76824 |
@@ -1,3 +1,7 @@
|
||||
# rumes
|
||||
|
||||
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
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user