Elixir Language Connecting nodes on the same machine


Example

Start two named nodes in two terminal windows:

>iex --name bob@127.0.0.1
iex(bob@127.0.0.1)>
>iex --name frank@127.0.0.1
iex(frank@127.0.0.1)>

Connect two nodes by instructing one node to connect:

iex(bob@127.0.0.1)> Node.connect :"frank@127.0.0.1"
true

The two nodes are now connected and aware of each other:

iex(bob@127.0.0.1)> Node.list
[:"frank@127.0.0.1"]
iex(frank@127.0.0.1)> Node.list
[:"bob@127.0.0.1"]

You can execute code on other nodes:

iex(bob@127.0.0.1)> greet = fn() -> IO.puts("Hello from #{inspect(Node.self)}") end
iex(bob@127.0.0.1)> Node.spawn(:"frank@127.0.0.1", greet)
#PID<9007.74.0>
Hello from :"frank@127.0.0.1"
:ok