#[cfg(not(all(windows, feature = "tokio")))]
fn main() {
#[rustfmt::skip] eprintln!("\
This example is not available on platforms other than Windows or when the \
Tokio feature is disabled.");
}
#[cfg(all(windows, feature = "tokio"))]
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
use {
interprocess::os::windows::named_pipe::{pipe_mode, tokio::*},
tokio::{
io::{AsyncReadExt, AsyncWriteExt},
try_join,
},
};
let name = r"\\.\pipe\Example";
let mut buffer = String::with_capacity(128);
let conn = DuplexPipeStream::<pipe_mode::Bytes>::connect_by_path(name).await?;
let [mut recver, mut sender] = [&conn; 2];
let send = async {
sender.write_all(b"Hello from client!").await?;
sender.shutdown().await?;
Ok(())
};
let recv = recver.read_to_string(&mut buffer);
try_join!(send, recv)?;
drop(conn);
println!("Server answered: {buffer}");
Ok(())
}