evnu
evnu

Reputation: 6680

Distributed Erlang: Learn about remote host and start function

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:

([email protected])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?

Upvotes: 0

Views: 331

Answers (1)

Isac
Isac

Reputation: 2068

There are two problems:

  1. You must set a common cookie for both nodes so they can interact.

    erl -sname dilbert -setcookie pointyhairedboss
    erl -sname dogbert -setcookie pointyhairedboss

  2. You must specify the hostname of the node you want to connect to. spawn('dogbert@yourhostname', fun () -> io:format("HELLO!") end).

Upvotes: 4

Related Questions