rust-lang-nursery / unix-socket

Unix socket support for Rust
Apache License 2.0
53 stars 18 forks source link

May I ask you to show me UnixStream example? #1

Closed ghmlee closed 9 years ago

ghmlee commented 9 years ago

Recently I found std::old_io::net::pipe::UnixStream will be deprecated and also some people mentioned your unix_socket. If you are not busy (of course you are busy), may I ask you to show me UnixStream example? Thanks. :)

sfackler commented 9 years ago

Sure - it's pretty straightforward. You open a UnixStream with the connect method which is passed the path to the unix socket file on the filesystem:

let mut socket = try!(UnixStream::connect("/run/postgres/.s.PGSQL.5432");

UnixStream implements Read and Write, so you can use it like any other stream:

let mut buf = vec![];
try!(socket.read_to_end(&mut buf));
ghmlee commented 9 years ago

@sfackler Thank you so much. :)