Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

In Elixir/Erlang, which port is used for `Node.connect`?

One can init a Elixir node by iex using:

iex --sname [email protected] --cookie foo

And then another one can connect this node in REPL using:

Node.connect(:"[email protected]")

It seems the connection is over TCP protocol. However, I didn't find a parameter in document to specify which port is used. Does anyone have any ideas about this?

like image 660
Hanfei Sun Avatar asked Feb 15 '16 12:02

Hanfei Sun


1 Answers

Connecting nodes is handled by the Erlang Port Mapping Daemon (epmd) which runs by default on port 4369. From the documentation:

A different port can be specified to allow several instances of epmd, representing independent clusters of nodes, to co-exist on the same host. All nodes in a cluster must use the same epmd port number.

The actual node opens a random(?) port and announces this along with its sname to the local epmd. When you now connect to '[email protected]', your Erlang VM will ask the remote epmd running on 10.99.1.50 on port 4369 for information on 'node1'. It will answer with the actual port number to which your process then connects directly.

like image 65
filmor Avatar answered Sep 21 '22 16:09

filmor