Skip to content

Instantly share code, notes, and snippets.

@badouralix
Created September 7, 2022 19:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save badouralix/4f68eafb4f9d55ee10a02cd1222b9315 to your computer and use it in GitHub Desktop.
Save badouralix/4f68eafb4f9d55ee10a02cd1222b9315 to your computer and use it in GitHub Desktop.
Dirty dump of solutions for https://protohackers.com
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