I'm trying to create a client that will send all data from stdin to a server. I can build the client, but I don't get a result if I enter the text, although I'm waiting for the message "send data" or an error.
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);
}