box-o-sand/httpong/src/main.rs

23 lines
507 B
Rust
Raw Normal View History

2021-06-01 12:49:27 +00:00
use std::env;
use std::net::{TcpListener, TcpStream};
fn handle_client(stream: TcpStream) {
println!("---> handling stream {:?}", stream);
// ...
}
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() {
handle_client(stream?);
}
Ok(())
}