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(()) }