Compare commits
No commits in common. "7ae9903d95e911cf243c6c5a19ae53cb6dbe51f0" and "05043d778a99efbbb257f3ab282898aa1e24bde3" have entirely different histories.
7ae9903d95
...
05043d778a
5
httpong/Cargo.lock
generated
5
httpong/Cargo.lock
generated
@ -1,5 +0,0 @@
|
|||||||
# This file is automatically @generated by Cargo.
|
|
||||||
# It is not intended for manual editing.
|
|
||||||
[[package]]
|
|
||||||
name = "httpong"
|
|
||||||
version = "0.1.0"
|
|
@ -1,9 +0,0 @@
|
|||||||
[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]
|
|
@ -1,37 +0,0 @@
|
|||||||
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(())
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user