mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-27 00:00:12 +02:00
Touch up examples to ensure consistency
This commit is contained in:
+22
-2
@@ -1,14 +1,34 @@
|
||||
//! A small example of a server that accepts TCP connections and writes out
|
||||
//! `Hello!` to them, afterwards closing the connection.
|
||||
//!
|
||||
//! You can test this out by running:
|
||||
//!
|
||||
//! cargo run --example hello
|
||||
//!
|
||||
//! and then in another terminal executing
|
||||
//!
|
||||
//! nc -4 localhost 8080
|
||||
//!
|
||||
//! You should see `Hello!` printed out and then the `nc` program will exit.
|
||||
|
||||
extern crate futures;
|
||||
extern crate tokio_core;
|
||||
extern crate env_logger;
|
||||
|
||||
use std::env;
|
||||
use std::net::SocketAddr;
|
||||
|
||||
use futures::stream::Stream;
|
||||
use tokio_core::reactor::Core;
|
||||
use tokio_core::net::TcpListener;
|
||||
|
||||
fn main() {
|
||||
env_logger::init().unwrap();
|
||||
let addr = env::args().nth(1).unwrap_or("127.0.0.1:8080".to_string());
|
||||
let addr = addr.parse::<SocketAddr>().unwrap();
|
||||
|
||||
let mut core = Core::new().unwrap();
|
||||
let address = "127.0.0.1:8080".parse().unwrap();
|
||||
let listener = TcpListener::bind(&address, &core.handle()).unwrap();
|
||||
let listener = TcpListener::bind(&addr, &core.handle()).unwrap();
|
||||
|
||||
let addr = listener.local_addr().unwrap();
|
||||
println!("Listening for connections on {}", addr);
|
||||
|
||||
Reference in New Issue
Block a user