1
Fork 0

Add demo for responses

This commit is contained in:
Jake Howard 2023-08-20 11:47:41 +01:00
parent 2aa154100c
commit 0a0b4218f9
Signed by: jake
GPG Key ID: 57AFB45680EDD477
1 changed files with 10 additions and 1 deletions

View File

@ -61,7 +61,7 @@ fn create_socket() -> PathBuf {
temp_dir
}
fn handle_client(stream: UnixStream) {
fn handle_client(mut stream: UnixStream) {
const TIMEOUT: Duration = Duration::from_secs(3);
let reader = BufReader::new(stream.try_clone().unwrap());
@ -96,6 +96,9 @@ fn handle_client(stream: UnixStream) {
for line in lines {
dbg!(line.unwrap());
// Panics if the socket dies mid-loop
writeln!(stream, "REPLY").unwrap();
}
println!("Closed - killing thread");
@ -104,6 +107,8 @@ fn handle_client(stream: UnixStream) {
fn client(path: String) {
let mut stream = UnixStream::connect(path).unwrap();
let reader = BufReader::new(stream.try_clone().unwrap());
thread::sleep(Duration::from_secs(2));
writeln!(stream, "handshake").unwrap();
@ -114,6 +119,10 @@ fn client(path: String) {
writeln!(stream, "Hello world").unwrap();
let resp = reader.lines().next();
dbg!(resp);
thread::sleep(Duration::from_secs(2));
}