cli communication added
parent
6e86dcbf09
commit
a75160c3e2
|
|
@ -4,6 +4,8 @@ version = "0.1.6"
|
||||||
edition = "2021"
|
edition = "2021"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
anyhow = "1.0.94"
|
||||||
clap = { version = "4.5.22", features = ["derive"] }
|
clap = { version = "4.5.22", features = ["derive"] }
|
||||||
serde = { version = "1.0.215", features = ["derive"] }
|
serde = { version = "1.0.215", features = ["derive"] }
|
||||||
serde_json = "1.0.133"
|
serde_json = "1.0.133"
|
||||||
|
tokio = { version = "1.42.0", features = ["full", "net"] }
|
||||||
|
|
|
||||||
|
|
@ -8,6 +8,7 @@ pub struct Cli {
|
||||||
)]
|
)]
|
||||||
command : Commands,
|
command : Commands,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, Subcommand)]
|
#[derive(Debug, Subcommand)]
|
||||||
pub enum Commands {
|
pub enum Commands {
|
||||||
#[command(
|
#[command(
|
||||||
|
|
|
||||||
|
|
@ -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<TcpStream> {
|
||||||
|
let stream = TcpStream::connect("127.0.0.1:7753").await?;
|
||||||
|
Ok(stream)
|
||||||
|
}
|
||||||
|
|
||||||
|
pub async fn try_send(stream: Result<TcpStream>, 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(())
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue