Created
May 27, 2024 11:48
-
-
Save kolektiv/5380a6bd940f854669db344153194f74 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::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