Skip to content

Instantly share code, notes, and snippets.

@sdjdd
Created October 25, 2022 04:05
Show Gist options
  • Save sdjdd/82af52681dcfeeb568e8c0b9cdca6c17 to your computer and use it in GitHub Desktop.
Save sdjdd/82af52681dcfeeb568e8c0b9cdca6c17 to your computer and use it in GitHub Desktop.
use std::io::{Read, Write};
use std::net::TcpListener;
fn main() {
let listener = TcpListener::bind("127.0.0.1:8080").unwrap();
for stream in listener.incoming() {
let mut stream = stream.unwrap();
std::thread::spawn(move || loop {
let mut buf = [0 as u8; 1024];
let n = stream.read(&mut buf).unwrap();
if n == 0 {
break;
}
stream.write(&buf[..n]).unwrap();
});
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment