pub fn bind(addr: SocketAddr) -> Server
Expand description
Creates a new Server
instance that binds to the provided address.
Examples found in repository?
More examples
examples/configure_http.rs (line 21)
10async fn main() {
11 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
12
13 let config = HttpConfig::new()
14 .http1_only(true)
15 .http2_only(false)
16 .max_buf_size(8192)
17 .build();
18
19 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
20 println!("listening on {}", addr);
21 hyper_server::bind(addr)
22 .http_config(config)
23 .serve(app.into_make_service())
24 .await
25 .unwrap();
26}
examples/shutdown.rs (line 23)
13async fn main() {
14 let app = Router::new().route("/", get(|| async { "Hello, world!" }));
15
16 let handle = Handle::new();
17
18 // Spawn a task to shutdown server.
19 tokio::spawn(shutdown(handle.clone()));
20
21 let addr = SocketAddr::from(([127, 0, 0, 1], 3000));
22 println!("listening on {}", addr);
23 hyper_server::bind(addr)
24 .handle(handle)
25 .serve(app.into_make_service())
26 .await
27 .unwrap();
28
29 println!("server is shut down");
30}
Additional examples can be found in: