问题
No matter what I try, I can't get two different nodes to communicate. This is probably a very simple problem to solve.
I have created the file .cookie.erlang and I've placed it into my home directory. Then I open a terminal window and type the following commands:
erl -sname user1@pc
erlang:set_cookie(node(),cookie).
In another terminal window I type:
erl -sname user2@pc
erlang:set_cookie(node(),cookie).
Now if I type the following command in the first terminal window:
net_adm:ping(user2@pc).
I always get "false" as result, meaning that the two nodes were not able to connect to each other. I don't understand what I am missing here...
回答1:
Definitely make sure that 'pc' is the actual hostname of your machine. If it's not, make sure you're using that.
Alternatively, since you're using sname and both hosts are on the same machine, you could get away with doing erl -sname user1
and erl -sname user2
.
回答2:
This is a DNS problem, please see here, which the answer of a similar problem
回答3:
Yes, it looks mostly a DNS issue. You should update it in /etc/hosts if you are on a Unix based OS, if it is on the same machine you can always use localhost that will be reachable:
erl -sname a@localhost -cookie aloha
Then in a separate terminal:
erl -sname b@localhost -cookie aloha
With that you should be able to communicate nodes just fine.
来源:https://stackoverflow.com/questions/13753741/cant-get-two-erlang-nodes-to-communicate