Asynchronous tcpclient based on aqueue actor.
DEMO URL:
examples echo:
#![feature(async_closure)]
use tcpclient::{TcpClient,SocketClientTrait};
use tokio::io::AsyncReadExt;
use std::error::Error;
use log::LevelFilter;
#[tokio::main]
async fn main()->Result<(),Box<dyn Error>> {
env_logger::Builder::new().filter_level(LevelFilter::Debug).init();
let client =
TcpClient::connect("127.0.0.1:5555", async move |_, client, mut reader| {
let mut buff=[0;7];
while let Ok(len) = reader.read_exact(&mut buff).await {
println!("{}",std::str::from_utf8(&buff[..len])?);
client.send(&buff[..len]).await?;
}
Ok(true)
}, ()).await?;
client.send(b"1234567").await?;
let mut str = "".into();
std::io::stdin().read_line(&mut str)?;
client.disconnect().await?;
std::io::stdin().read_line(&mut str)?;
Ok(())
}