Skip to content

Commit 90fb3be

Browse files
specify the address to send
1 parent 2634459 commit 90fb3be

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

src/main.rs

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use tokio::{
88
async fn main() {
99
let listener = TcpListener::bind("localhost:8080").await.unwrap();
1010

11-
let (tx, _rx) = broadcast::channel::<String>(10);
11+
let (tx, _rx) = broadcast::channel(10);
1212

1313
loop {
14-
let (mut socket, _addr) = listener.accept().await.unwrap();
14+
let (mut socket, addr) = listener.accept().await.unwrap();
1515

1616
let tx = tx.clone();
1717
let mut rx = tx.subscribe();
@@ -29,14 +29,17 @@ async fn main() {
2929
break;
3030
}
3131

32-
tx.send(line.clone()).unwrap();
32+
tx.send((line.clone(), addr)).unwrap();
3333
line.clear();
3434
}
3535
result = rx.recv() => {
36-
let msg = result.unwrap();
36+
let (msg, other_addr) = result.unwrap();
37+
38+
if addr != other_addr{
39+
// write every single byte in the buffer
40+
writer.write_all(msg.as_bytes()).await.unwrap();
41+
}
3742

38-
// write every single byte in the buffer
39-
writer.write_all(msg.as_bytes()).await.unwrap();
4043
}
4144
}
4245
}

0 commit comments

Comments
 (0)