diff --git a/src/main.rs b/src/main.rs index eac84b6..70cfab0 100644 --- a/src/main.rs +++ b/src/main.rs @@ -5,10 +5,10 @@ use tokio::sync::broadcast; #[tokio::main] async fn main() { let listener = TcpListener::bind("localhost:8080").await.unwrap(); - let (tx, _) = broadcast::channel::(10); + let (tx, _) = broadcast::channel(10); loop { - let (mut socket, _) = listener.accept().await.unwrap(); + let (mut socket, addr) = listener.accept().await.unwrap(); let tx = tx.clone(); let mut rx = tx.subscribe(); @@ -25,12 +25,14 @@ async fn main() { if result.unwrap() == 0 { break; } - tx.send(line.clone()).unwrap(); + tx.send((line.clone(),addr)).unwrap(); line.clear(); } result = rx.recv() =>{ - let message = result.unwrap(); - writer.write_all(&message.as_bytes()).await.unwrap(); + let (message,other_addr) = result.unwrap(); + if addr != other_addr{ + writer.write_all(&message.as_bytes()).await.unwrap(); + } } } }