Nodes

Other topics

List all visible nodes in the system

Connecting nodes on the same machine

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

Connecting nodes on different machines

Start a named process on one IP address:

$ iex --name [email protected] --cookie chocolate
iex([email protected])> Node.ping :"[email protected]"
:pong
iex([email protected])> Node.list
[:"[email protected]"]

Start another named process on a different IP address:

$ iex --name [email protected] --cookie chocolate
iex([email protected])> Node.list
[:"[email protected]"]

Contributors

Topic Id: 2065

Example Ids: 6759,6760,6761

This site is not affiliated with any of the contributors.