Skip to content

Instantly share code, notes, and snippets.

@jD91mZM2
Created June 14, 2018 06:22
Show Gist options
  • Save jD91mZM2/7eadb511c9cff15794b57c1c626c3b86 to your computer and use it in GitHub Desktop.
Save jD91mZM2/7eadb511c9cff15794b57c1c626c3b86 to your computer and use it in GitHub Desktop.
use std::{
io::prelude::*,
os::unix::net::{UnixListener, UnixStream},
thread
};
fn main() {
let server = UnixListener::bind("/tmp/uds-demo").unwrap();
thread::spawn(move || {
let (mut stream, _addr) = server.accept().unwrap();
stream.write(b"Hello World").unwrap();
});
let mut client = UnixStream::connect("/tmp/uds-demo").unwrap();
let mut buf = [0; 32];
let n = client.read(&mut buf).unwrap();
assert_eq!(&buf[..n], b"Hello World");
println!("It works!");
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment