diff --git a/noxis-cli/Cargo.toml b/noxis-cli/Cargo.toml index fa4af59..22666eb 100644 --- a/noxis-cli/Cargo.toml +++ b/noxis-cli/Cargo.toml @@ -4,6 +4,8 @@ version = "0.1.6" edition = "2021" [dependencies] +anyhow = "1.0.94" clap = { version = "4.5.22", features = ["derive"] } serde = { version = "1.0.215", features = ["derive"] } serde_json = "1.0.133" +tokio = { version = "1.42.0", features = ["full", "net"] } diff --git a/noxis-cli/src/cli.rs b/noxis-cli/src/cli.rs index 7be94f6..677e721 100644 --- a/noxis-cli/src/cli.rs +++ b/noxis-cli/src/cli.rs @@ -7,7 +7,8 @@ pub struct Cli { help = "to manage Noxis work", )] command : Commands, -} +} + #[derive(Debug, Subcommand)] pub enum Commands { #[command( diff --git a/noxis-cli/src/net.rs b/noxis-cli/src/net.rs new file mode 100644 index 0000000..d607c8c --- /dev/null +++ b/noxis-cli/src/net.rs @@ -0,0 +1,26 @@ +use tokio::net::TcpStream; +use tokio::io::AsyncWriteExt; +use tokio::time::{Duration, sleep}; +use anyhow::Result; +use super::Cli; + + +pub async fn create_tcp_stream() -> Result { + let stream = TcpStream::connect("127.0.0.1:7753").await?; + Ok(stream) +} + +pub async fn try_send(stream: Result, params: Cli) -> Result<()> { + let mut stream = stream?; + loop { + if stream.writable().await.is_err() { + sleep(Duration::from_millis(100)).await; + continue; + } + let msg = format!("{:?}", params); + // let msg = r"HTTP/1.1 POST\r\nContent-Length: 14\r\nContent-Type: text/plain\r\n\r\nHello, World!@"; + stream.write_all(msg.as_bytes()).await?; + // ... + } + Ok(()) +} \ No newline at end of file