I am trying to implement a really simple example to get a first look into Distributed Erlang. So, I start two nodes on the same machine:
erl -sname dilbert
erl -sname dogbert
The task is that dogbert makes dilbert output Hello, World! using a simple fun () -> io:format("Hello, World!") end on node dilbert. I thought this would be easy with dogbert‘s shell:
(dogbert@centraldogma.fubar)1> spawn(dilbert, fun () -> io:format("HELLO!") end).
<0.39.0>
=ERROR REPORT==== 13-Jun-2012::17:49:04 ===
** Can not start erlang:apply,[#Fun<erl_eval.20.82930912>,[]] on dilbert **
In the same shell, using nodes(). outputs []. Well, dogbert obviously doesn’t know about dilbert, but why is that the case? Or, how do I make nodes in distributed erlang get to know each other?
There are two problems:
You must set a common cookie for both nodes so they can interact.
erl -sname dilbert -setcookie pointyhairedboss
erl -sname dogbert -setcookie pointyhairedboss
You must specify the hostname of the node you want to connect to.
spawn(‘dogbert@yourhostname’, fun () -> io:format(“HELLO!”) end).