Fun with tcp

cat-town
Dan Buch 3 years ago
parent 05043d778a
commit 8f3897e097
Signed by: meatballhat
GPG Key ID: 9685130D8B763EA7

5
httpong/Cargo.lock generated

@ -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"

@ -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]

@ -0,0 +1,22 @@
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(())
}
Loading…
Cancel
Save