Created
September 7, 2022 19:15
-
-
Save badouralix/4f68eafb4f9d55ee10a02cd1222b9315 to your computer and use it in GitHub Desktop.
Dirty dump of solutions for https://protohackers.com
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::prelude::*; | |
use std::net::{TcpListener, TcpStream}; | |
fn handle_client(mut stream: TcpStream) { | |
println!("Youpi"); | |
let mut buffer = Vec::new(); | |
stream.read_to_end(&mut buffer).unwrap(); | |
println!("{}", buffer.len()); | |
// println!("{buffer:?}"); | |
stream.write(&buffer).unwrap(); | |
} | |
fn main() -> std::io::Result<()> { | |
// ssh -R 8090:localhost:8090 <remote> "socat TCP-LISTEN:8091,fork,bind=0.0.0.0 TCP:localhost:8090" | |
let listener = TcpListener::bind("127.0.0.1:8090")?; | |
// accept connections and process them serially | |
for stream in listener.incoming() { | |
handle_client(stream?); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment