summaryrefslogtreecommitdiffstats
path: root/examples
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2017-09-11 08:07:38 -0700
committerAlex Crichton <alex@alexcrichton.com>2017-09-11 08:07:38 -0700
commit5e4cfdfab114e9c1913a98b40746727b4d2cf5a4 (patch)
tree5a3bf03b2c3a4fe266260e28501a730a31a721fc /examples
parente0b751b0137fb1cf572e07fa6463f5f984f7e9a7 (diff)
Recommend the `connect` example over `nc`
Diffstat (limited to 'examples')
-rw-r--r--examples/chat.rs2
-rw-r--r--examples/hello.rs2
-rw-r--r--examples/sink.rs15
3 files changed, 9 insertions, 10 deletions
diff --git a/examples/chat.rs b/examples/chat.rs
index 0e05c8ad..039fb685 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 a22517a5..0d7a0ebc 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 bd56001f..d709178d 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::<SocketAddr>().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<()> {