Skip to content

Instantly share code, notes, and snippets.

@kolektiv
Created May 27, 2024 11:48
Show Gist options
  • Save kolektiv/5380a6bd940f854669db344153194f74 to your computer and use it in GitHub Desktop.
Save kolektiv/5380a6bd940f854669db344153194f74 to your computer and use it in GitHub Desktop.
use std::{
io::Read,
os::unix::net::UnixStream,
};
use anyhow::Result;
use test_shared::Test;
fn main() -> Result<()> {
println!("creating stream, connecting...");
let mut bytes = [0, 0, 0, 0, 0, 0, 0, 0];
let mut stream = UnixStream::connect("/tmp/test_socket")?;
stream.set_read_timeout(None)?;
stream.set_nonblocking(false)?;
loop {
let _ = stream.read_exact(&mut bytes)?;
let length = usize::from_be_bytes(bytes);
println!("got length prefix of {length}");
let mut bytes = vec![0u8; length];
let _ = stream.read_exact(&mut bytes[..])?;
let test: Test = bincode::deserialize(&bytes[..])?;
println!("Received Test: {test:#?}");
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment