Erlang: Unix Domain Socket Support

erlang: UNIX domain socket support?

Erlang/OTP comes with drivers for tcp and udp sockets only. So...

No.

Third part drivers

  • unixdom_drv in http://jungerl.sourceforge.net/
  • uds_dist in the source tree's driver examples
  • procket at https://github.com/msantos/procket

How do unix domain sockets work in Erlang 19

I've not tried the official release 19, but I can make it work using the latest git (as of July 7th) by:

  1. disabling active with {active, false}
  2. using UNIX-SENDTO instead of UNIX-CONNECT
  3. binding socat's socket to its own address (not binding creates an error on erlangs side when resolving the address.)

Demonstration:

console 1:

$ rm /tmp/socket*
$ erl
Erlang/OTP 19 [erts-8.0.1] [source-ca40008] [64-bit] [smp:2:2] [async-threads:10] [hipe] [kernel-poll:false]

Eshell V8.0.1 (abort with ^G)
1> {ok, Port} = gen_udp:open(0, [{active, false},{ifaddr, {local,"/tmp/socket2"}}]),
1> io:format("ok~w ~w~n", [ok,Port]),
1> gen_udp:recv(Port, 2).
okok #Port<0.451>

console 2:

 $ echo "hi" |  socat - UNIX-SENDTO:/tmp/socket2,bind=/tmp/socket1

console 1 results:

okok #Port<0.451>
{ok,{{local,<<"/tmp/socket1">>},0,"hi\n"}}

How to do IPC using Unix Domain Socket in D?

After binding, you actually need to accept. It will return a new Socket instance which you can actually receive from. Your client side branch looks ok. I think that is your key mistake here.

I also have a code sample in my book that shows basic functionality of std.socket which can help as an example:
http://arsdnet.net/dcode/book/chapter_02/03/

it is tcp, but making it unix just means changing the family, like you already did in your code.

You can also look up socket tutorials for C and so on, the D socket is just a thin wrapper around those same BSD style socket functions.

Same Machine Erlang communication

R1. It uses TCP/IP (in fact, there isn't any "standard" support for UNIX domain sockets)

R2. I am pretty sure it is still TCP/IP sockets

R3. see R2

R4. There is a binary exchange format proper to Erlang and it is message based. Exchanges can either be sync (RPC-like) or async.

R5. No master.


As bonus (to help you save time): don't forget to use a registered name (-sname or -name) in order to use inter-node communications (either RPC or whatever).

Having dotnet core 2.0.0 Socket.Listen() support UNIX Domain Socket?

It looks like @stephentoub replied with the answer on your corresponding GitHub issue.

Did you try SocketType.Stream instead of SocketType.Dgram?



Related Topics



Leave a reply



Submit