Start two named nodes in two terminal windows:
>iex --name [email protected]
iex([email protected])>
>iex --name [email protected]
iex([email protected])>
Connect two nodes by instructing one node to connect:
iex([email protected])> Node.connect :"[email protected]"
true
The two nodes are now connected and aware of each other:
iex([email protected])> Node.list
[:"[email protected]"]
iex([email protected])> Node.list
[:"[email protected]"]
You can execute code on other nodes:
iex([email protected])> greet = fn() -> IO.puts("Hello from #{inspect(Node.self)}") end
iex([email protected])> Node.spawn(:"[email protected]", greet)
#PID<9007.74.0>
Hello from :"[email protected]"
:ok