diff --git a/src/main.rs b/src/main.rs index 84dbd32..bd931c3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -48,6 +48,7 @@ fn main() -> Result <(), Error> println! ("{} ms", (stop - start).as_millis ()); }, + Some ("network") => main_network (), Some (_) => eprintln! ("Unknown subcommand"), } @@ -199,6 +200,41 @@ fn main_egui () eframe::run_native("Five Five Five", native_options, Box::new(|cc| Box::new(App::new(cc, send_to_ctl, recv_at_gui, send_gui_handle)))).unwrap (); } +fn main_network () +{ + use tokio::io:: + { + AsyncReadExt, + AsyncWriteExt, + }; + + let rt = tokio::runtime::Runtime::new ().unwrap (); + + rt.block_on (async + { + let server = tokio::net::TcpListener::bind ("127.0.0.1:9001").await.unwrap (); + + tokio::spawn (async move + { + while let Ok ((mut stream, _remote_addr)) = server.accept ().await + { + tokio::spawn (async move + { + for i in 0.. + { + let mut buf = vec! [0u8]; + if let Err (_) = stream.read_exact (&mut buf).await + { + break; + } + stream.write_all (format! ("{i}\n").as_bytes ()).await.unwrap (); + } + }); + } + }).await.unwrap (); + }); +} + #[derive (Debug, thiserror::Error)] enum Error {