Last active
July 2, 2019 10:16
-
-
Save alessiodionisi/fd90b08229c8a6a3a0b4728bda546a69 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; | |
use std::io::prelude::*; | |
use std::net::{TcpListener, TcpStream}; | |
use std::thread; | |
fn handle_connection(mut stream: TcpStream) { | |
let mut buffer = [0; 512]; | |
loop { | |
stream.read(&mut buffer).unwrap(); | |
// println!("request: {}", String::from_utf8_lossy(&buffer[..])); | |
let response = "+OK\r\n"; | |
stream.write(response.as_bytes()).unwrap(); | |
stream.flush().unwrap(); | |
} | |
} | |
fn main() -> io::Result<()> { | |
let listener = TcpListener::bind("[::1]:4343").unwrap(); | |
for stream in listener.incoming() { | |
let stream = stream.unwrap(); | |
thread::spawn(|| { | |
handle_connection(stream); | |
}); | |
} | |
Ok(()) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment