I'd like to read messages from a Unix Domain socket (SOCK_STREAM) but I'm having difficulty finding a working example of doing that in Elixir. I've been trying to make it work with the procket library from Erlang, but I've had nothing but trouble.
Can anyone show me a working example of reading from a unix domain socket in Elixir?
Here is a nice example, using :procket.
open
functions get a tuple of file descriptors {stdin, stdout}
from a connection address, either IPv4, IPv6 or unix domain socket.
EDIT: It's used here to initialize a port, but using http://elixir-lang.org/docs/stable/elixir/IO.html
it's easy to read from.
There's no support for Unix Sockets in vanilla Erlang nor in Elixir.
Still there are couple of solutions, provided as C-extensions. One is already mentioned procket, other is afunix.
I find examples in the afunix
readme pretty straightforward and easy to brain-translate to Elixir (remember to lowercase the vars and use apostrophes '
instead of quotes "
!).
[EDIT]
Erlang project (as long as it's rebar-ized, both above are) can be easily added to your Mix project by adding to deps the following tuple (shamelessly promoting mentioned afunix
for no reason :) :
{:afunix, github: "tonyrog/afunix"}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With