1

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);
}
Shepmaster
  • 388,571
  • 95
  • 1,107
  • 1,366
aitvann
  • 1,289
  • 2
  • 8
  • 10
  • Possible duplicate of [How can I stop reading from a tokio::io::lines stream?](https://stackoverflow.com/questions/56555513/how-can-i-stop-reading-from-a-tokioiolines-stream) – Ömer Erden Jun 17 '19 at 14:42

0 Answers0