Created
October 25, 2022 04:05
-
-
Save sdjdd/82af52681dcfeeb568e8c0b9cdca6c17 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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