Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Unix Domain Sockets in Elixir

Tags:

elixir

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?

like image 365
Kevin Thompson Avatar asked Jan 10 '16 22:01

Kevin Thompson


2 Answers

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.

like image 198
Lisael Avatar answered Sep 23 '22 23:09

Lisael


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"}

like image 29
Wojciech Kaczmarek Avatar answered Sep 22 '22 23:09

Wojciech Kaczmarek