Files
hyper/examples/multi_server.rs
Sean McArthur d127201ef2 feat(rt): make tokio runtime optional
A Cargo feature `runtime` is added, which is enabled by default, that
includes the following:

- The `client::HttpConnector`, which uses `tokio::net::TcpStream`.
- The `server::AddrStream`, which uses `tokio::net::TcpListener`.
- The `hyper::rt` module, which includes useful utilities to work with
  the runtime without needing to import `futures` or `tokio` explicity.

Disabling the feature removes many of these niceties, but allows people
to use hyper in environments that have an alternative runtime, without
needing to download an unused one.
2018-04-23 16:56:26 -07:00

35 lines
959 B
Rust

#![deny(warnings)]
extern crate hyper;
extern crate pretty_env_logger;
use hyper::{Body, Response, Server};
use hyper::service::service_fn_ok;
use hyper::rt::{self, Future};
static INDEX1: &'static [u8] = b"The 1st service!";
static INDEX2: &'static [u8] = b"The 2nd service!";
fn main() {
pretty_env_logger::init();
let addr1 = ([127, 0, 0, 1], 1337).into();
let addr2 = ([127, 0, 0, 1], 1338).into();
rt::run(rt::lazy(move || {
let srv1 = Server::bind(&addr1)
.serve(|| service_fn_ok(|_| Response::new(Body::from(INDEX1))))
.map_err(|e| eprintln!("server 1 error: {}", e));
let srv2 = Server::bind(&addr2)
.serve(|| service_fn_ok(|_| Response::new(Body::from(INDEX2))))
.map_err(|e| eprintln!("server 2 error: {}", e));
println!("Listening on http://{} and http://{}", addr1, addr2);
rt::spawn(srv1);
rt::spawn(srv2);
Ok(())
}));
}