SHARE
TWEET

Untitled

a guest Jun 16th, 2019 77 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. extern crate tokio; // 0.1.21
  2. extern crate futures; // 0.1.27
  3.  
  4. use tokio::io::lines;
  5. use tokio::net::{TcpStream, TcpListener};
  6. use tokio::prelude::*;
  7.  
  8. fn main() {
  9.     let addr = "127.0.0.1:10228".parse().unwrap();
  10.     let listener = TcpListener::bind(&addr)
  11.         .expect("Unable to bind");
  12.    
  13.     let server = listener.incoming().for_each(move |mut sock| {
  14.         let (reader, writer) = sock.split();
  15.         let buffer = Vec::new();
  16.    
  17.         let handle_conn = tokio::io::read(reader, buffer)
  18.             .and_then(move |(r, b, len)| {
  19.                 println!("Got {:?}\namount of bytes: {}", b, len);
  20.                 Ok(())
  21.             }).map_err(|e| {error!("{}", e)});
  22.         tokio::spawn(handle_conn);
  23.         Ok(())
  24.     }).map_err(|e| {error!("{}", e)});
  25.    
  26.     tokio::run(server);
  27. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top