Fun with tcp
This commit is contained in:
parent
05043d778a
commit
8f3897e097
5
httpong/Cargo.lock
generated
Normal file
5
httpong/Cargo.lock
generated
Normal 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"
|
9
httpong/Cargo.toml
Normal file
9
httpong/Cargo.toml
Normal 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]
|
22
httpong/src/main.rs
Normal file
22
httpong/src/main.rs
Normal file
@ -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…
Reference in New Issue
Block a user