Created
March 15, 2023 16:20
-
-
Save micromaomao/d71727bb44d84b453c903edaad833bf9 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
FROM rust | |
WORKDIR /usr/src/fakesas | |
COPY . . | |
RUN cargo build --release | |
CMD ["./target/release/fakesas"] |
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; | |
use std::net::{TcpListener, TcpStream}; | |
fn main() -> Result<(), Box<dyn std::error::Error>> { | |
let tcpl = TcpListener::bind("0.0.0.0:6761")?; | |
loop { | |
let a = tcpl.accept(); | |
if let Err(ref e) = a { | |
eprintln!("Error accepting connection: {}", e); | |
} | |
let (mut astream, peer) = a.unwrap(); | |
println!("Accepted connection from {}", peer); | |
std::thread::spawn(move || { | |
let mut buf = vec![0u8; 1 << 16]; | |
loop { | |
let res = astream.read(&mut buf); | |
if let Err(ref e) = res { | |
eprintln!("Error reading from {}: {}", peer, e); | |
break; | |
} else if res.unwrap() == 0 { | |
println!("Connection from {} closed", peer); | |
break; | |
} | |
} | |
}); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment