add echo server
This commit is contained in:
parent
37194bab9f
commit
2bdee1320a
3 changed files with 37 additions and 0 deletions
7
Cargo.lock
generated
Normal file
7
Cargo.lock
generated
Normal file
|
@ -0,0 +1,7 @@
|
||||||
|
# This file is automatically @generated by Cargo.
|
||||||
|
# It is not intended for manual editing.
|
||||||
|
version = 3
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "protohackers"
|
||||||
|
version = "0.1.0"
|
|
@ -5,4 +5,7 @@ edition = "2021"
|
||||||
|
|
||||||
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
|
||||||
|
|
||||||
|
[[bin]]
|
||||||
|
name = "smoke"
|
||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
|
|
27
src/bin/smoke.rs
Normal file
27
src/bin/smoke.rs
Normal file
|
@ -0,0 +1,27 @@
|
||||||
|
use std::{io::{Read, Write}, net::TcpListener};
|
||||||
|
|
||||||
|
const PORT: usize = 10000;
|
||||||
|
const BUFF_SIZE: usize = 1;
|
||||||
|
fn main() -> std::io::Result<()> {
|
||||||
|
|
||||||
|
let listener = TcpListener::bind(format!("127.0.0.1:{PORT}"))?;
|
||||||
|
|
||||||
|
for stream in listener.incoming() {
|
||||||
|
match stream {
|
||||||
|
Ok(mut stream) => {
|
||||||
|
loop {
|
||||||
|
let mut buf: [u8; BUFF_SIZE] = [0; BUFF_SIZE];
|
||||||
|
|
||||||
|
if let Ok(_) = stream.read_exact(&mut buf) {
|
||||||
|
stream.write(&buf)?;
|
||||||
|
} else {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => panic!("{:?}", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Ok(())
|
||||||
|
}
|
Loading…
Add table
Reference in a new issue