File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff line change @@ -8,10 +8,10 @@ use tokio::{
88async 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 }
You can’t perform that action at this time.
0 commit comments