From 5e4cfdfab114e9c1913a98b40746727b4d2cf5a4 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 11 Sep 2017 08:07:38 -0700 Subject: [PATCH] Recommend the `connect` example over `nc` --- examples/chat.rs | 2 +- examples/hello.rs | 2 +- examples/sink.rs | 15 +++++++-------- 3 files changed, 9 insertions(+), 10 deletions(-) diff --git a/examples/chat.rs b/examples/chat.rs index 0e05c8ad4..039fb6859 100644 --- a/examples/chat.rs +++ b/examples/chat.rs @@ -10,7 +10,7 @@ //! //! And then in another window run: //! -//! nc -4 localhost 8080 +//! cargo run --example connect 127.0.0.1:8080 //! //! You can run the second command in multiple windows and then chat between the //! two, seeing the messages from the other client as they're received. For all diff --git a/examples/hello.rs b/examples/hello.rs index a22517a5a..0d7a0ebcb 100644 --- a/examples/hello.rs +++ b/examples/hello.rs @@ -7,7 +7,7 @@ //! //! and then in another terminal executing //! -//! nc -4 localhost 8080 +//! cargo run --example connect 127.0.0.1:8080 //! //! You should see `Hello!` printed out and then the `nc` program will exit. diff --git a/examples/sink.rs b/examples/sink.rs index bd56001f9..d709178dc 100644 --- a/examples/sink.rs +++ b/examples/sink.rs @@ -11,7 +11,7 @@ //! //! And then you can connect to it via: //! -//! nc -4 localhost 8080 > /dev/null +//! cargo run --example connect 127.0.0.1:8080 > /dev/null //! //! You should see your CPUs light up as data's being shove into the ether. @@ -35,17 +35,16 @@ fn main() { let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string()); let addr = addr.parse::().unwrap(); - let mut l = Core::new().unwrap(); - let socket = TcpListener::bind(&addr, &l.handle()).unwrap(); + let mut core = Core::new().unwrap(); + let handle = core.handle(); + let socket = TcpListener::bind(&addr, &handle).unwrap(); println!("Listening on: {}", addr); - let server = socket.incoming().and_then(|(socket, addr)| { + let server = socket.incoming().for_each(|(socket, addr)| { println!("got a socket: {}", addr); - write(socket).or_else(|_| Ok(())) - }).for_each(|()| { - println!("lost the socket"); + handle.spawn(write(socket).or_else(|_| Ok(()))); Ok(()) }); - l.run(server).unwrap(); + core.run(server).unwrap(); } fn write(socket: TcpStream) -> IoFuture<()> {