From e8f757457b7d34c3f019c858cc423a9934aff305 Mon Sep 17 00:00:00 2001 From: Carl Lerche Date: Wed, 23 Aug 2017 11:24:54 -0700 Subject: [PATCH] Update server example --- examples/server.rs | 37 ++++++++++--------------------------- 1 file changed, 10 insertions(+), 27 deletions(-) diff --git a/examples/server.rs b/examples/server.rs index f1fcff1..cee18dc 100644 --- a/examples/server.rs +++ b/examples/server.rs @@ -1,5 +1,6 @@ extern crate h2; extern crate http; +extern crate bytes; extern crate futures; extern crate tokio_io; extern crate tokio_core; @@ -9,6 +10,7 @@ extern crate env_logger; use h2::server::Server; use http::*; +use bytes::*; use futures::*; use tokio_core::reactor; @@ -27,7 +29,8 @@ pub fn main() { println!("listening on {:?}", listener.local_addr()); let server = listener.incoming().for_each(move |(socket, _)| { - let socket = io_dump::Dump::to_stdout(socket); + // let socket = io_dump::Dump::to_stdout(socket); + let connection = Server::handshake(socket) .then(|res| { @@ -46,34 +49,14 @@ pub fn main() { println!(" error responding; err={:?}", e); } + println!(">>>> sending data"); + stream.send_data(Bytes::from_static(b"hello world"), true).unwrap(); + + Ok(()) + }).and_then(|_| { + println!("~~~~~~~~~~~~~~~~~~~~~~~~~~~ H2 connection CLOSE !!!!!! ~~~~~~~~~~~"); Ok(()) }) - - /* - // Receive a request - conn.into_future() - .then(|res| { - let (frame, conn) = res.unwrap(); - println!("Zomg frame; {:?}", frame); - - conn.into_future() - }) - .then(|res| { - let (frame, conn) = res.unwrap(); - println!("Zomg frame; {:?}", frame); - - let mut response = response::Head::default(); - response.status = status::OK; - - conn.send_response(1.into(), response, false) - }) - .then(|res| { - let conn = res.unwrap(); - println!("... sending next frame"); - - conn.send_data(1.into(), "world".into(), true) - }) - */ }) .then(|res| { let _ = res.unwrap();