我正在尝试创建一个客户端,该客户端会将所有数据从stdin发送到服务器。我可以构建客户端,但是尽管我在等待消息“发送数据”或错误,但是输入文本却没有结果。
use tokio::{
codec, io as aio, net as anet,
prelude::{future::Future, stream::Stream},
};
fn main() {
let address = "127.0.0.1:4732"
.parse()
.expect("could not to parse address");
let stdin_stream = {
let stdin = aio::stdin();
let codec = codec::LinesCodec::new();
codec::FramedRead::new(stdin, codec)
};
let client = anet::TcpStream::connect(&address)
.map_err(|err| eprintln!("connect error: {}", err))
.map(|stream| {
let codec = codec::LinesCodec::new();
codec::FramedWrite::new(stream, codec)
})
.and_then(move |sink| {
stdin_stream
.forward(sink)
.map_err(|err| eprintln!("could not forward stdin to stream: {}", err))
.map(|_| println!("send data"))
});
tokio::run(client);
}