diff options
Diffstat (limited to 'async-await/src/echo_client.rs')
-rw-r--r-- | async-await/src/echo_client.rs | 50 |
1 files changed, 0 insertions, 50 deletions
diff --git a/async-await/src/echo_client.rs b/async-await/src/echo_client.rs deleted file mode 100644 index 302b7ea2..00000000 --- a/async-await/src/echo_client.rs +++ /dev/null @@ -1,50 +0,0 @@ -#![feature(await_macro, async_await)] - -use tokio::async_wait; -use tokio::net::TcpStream; -use tokio::prelude::*; - -use std::io; -use std::net::SocketAddr; - -const MESSAGES: &[&str] = &[ - "hello", - "world", - "one two three", -]; - -async fn run_client(addr: &SocketAddr) -> io::Result<()> { - let mut stream = async_wait!(TcpStream::connect(addr))?; - - // Buffer to read into - let mut buf = [0; 128]; - - for msg in MESSAGES { - println!(" > write = {:?}", msg); - - // Write the message to the server - async_wait!(stream.write_all_async(msg.as_bytes()))?; - - // Read the message back from the server - async_wait!(stream.read_exact_async(&mut buf[..msg.len()]))?; - - assert_eq!(&buf[..msg.len()], msg.as_bytes()); - } - - Ok(()) -} - -#[tokio::main] -async fn main() { - use std::env; - - let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string()); - let addr = addr.parse::<SocketAddr>().unwrap(); - - // Connect to the echo serveer - - match async_wait!(run_client(&addr)) { - Ok(_) => println!("done."), - Err(e) => eprintln!("echo client failed; error = {:?}", e), - } -} |