shuffle shuffle

This commit is contained in:
2021-09-12 10:55:12 -04:00
parent 278ec88944
commit 7e976ccc6f
23 changed files with 0 additions and 0 deletions

5
rustbook/httpong/Cargo.lock generated Normal file
View File

@@ -0,0 +1,5 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
name = "httpong"
version = "0.1.0"

View File

@@ -0,0 +1,9 @@
[package]
name = "httpong"
version = "0.1.0"
authors = ["Dan Buch <dan@meatballhat.com>"]
edition = "2018"
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
[dependencies]

View File

@@ -0,0 +1,37 @@
use std::env;
use std::io::Read;
use std::net::{TcpListener, TcpStream};
fn handle_client(stream: &mut TcpStream) -> std::io::Result<()> {
println!("---> handling stream {:?}", stream);
let mut buf = [0; 1024];
let n = stream.read(&mut buf[..])?;
let req = std::str::from_utf8(&buf[..n]);
match req {
Ok(s) => {
println!("---> first {} bytes: {:?}", n, s);
Ok(())
}
Err(e) => {
println!("---> oh no {:?}", e);
Ok(())
}
}
}
fn main() -> std::io::Result<()> {
let mut addr = String::from("127.0.0.1:19721");
if let Ok(v) = env::var("ADDR") {
addr = String::from(v.as_str());
}
println!("listening at {}", addr);
let listener = TcpListener::bind(addr)?;
for stream in listener.incoming() {
if let Ok(_) = handle_client(&mut stream?) {
println!("---> looks like that went well")
}
}
Ok(())
}