You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
#![feature(async_closure)]use tcpclient::{TcpClient,SocketClientTrait};use tokio::io::AsyncReadExt;use std::error::Error;use log::LevelFilter;#[tokio::main]asyncfnmain()->Result<(),Box<dynError>>{// set logger out
env_logger::Builder::new().filter_level(LevelFilter::Debug).init();// connect echo serverlet client =
TcpClient::connect("127.0.0.1:5555",asyncmove |_, client,mut reader| {// read buff from target serverletmut buff=[0;7];whileletOk(len) = reader.read_exact(&mut buff).await{// send buff to target serverprintln!("{}",std::str::from_utf8(&buff[..len])?);
client.send(&buff[..len]).await?;}// return true need disconnect,false not disconnect// if true and the current state is disconnected, it will be ignored.Ok(true)},()).await?;// connect ok send buff to target server
client.send_all_ref(b"1234567").await?;// test disconnect readline letmut str = "".into();
std::io::stdin().read_line(&mut str)?;// disconnect target server
client.disconnect().await?;// wait env logger out show
std::io::stdin().read_line(&mut str)?;Ok(())}