Created
June 14, 2018 06:22
-
-
Save jD91mZM2/7eadb511c9cff15794b57c1c626c3b86 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::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