Unix domain sockets in Elixir

I would like to read messages from the Unix Domain socket (SOCK_STREAM), but I find it hard to find a working example of this in Elixir. I tried to get it to work with the Erlang leak library, but I had nothing but trouble.

Can someone show me a working example of reading from a unix domain socket in Elixir?

+5
source share
2 answers

Here is a good example using : procket .

open functions receive a tuple of file descriptors {stdin, stdout} from the connection address, IPv4, IPv6 or unix of a domain socket.

EDIT: it is used here to initialize the port, but using http://elixir-lang.org/docs/stable/elixir/IO.html it is easy to read.

+3
source

No Unix Sockets support in vanilla Erlang or Elixir.

However, there are several solutions provided as C-extensions. One of them is already mentioned procket , the other is afunix .

I find the examples in afunix readme quite simple and easy for the brain to translate into Elixir (remember to make amends for vars and use the apostrophes ' instead of quotation marks " !).

[EDIT]

An Erlang project (as long as it is reinforcing, both of the above) can easily be added to your Mix project by adding the following tuple to it (shamelessly promoting the aforementioned afunix no reason :):

{:afunix, github: "tonyrog/afunix"}

+2
source

Source: https://habr.com/ru/post/1240292/


All Articles