The basic unit of erlang distributed programming is erlang node. To find an erlang node is a prerequisite for running program on it. The configuration of /etc/hosts and domain resolving may affect. The issue came to me when I tested discoproject on two computers and got "Node failure".
Let's start with the classic example in Pragmatic Programming Erlang. First we start two erlang shell on the same machine, one named gandalf, the other named bilbo:
erl -sname gandalf
erl -sname bilbo
In node bilbo, you try "net_adm:ping(gandalf@localhost)." and you suppose to get a "pong" as response. Unfortunately, this may not happen on every computers, it is highly possible you may get a "pang" or some error massage. But you may start erlang shells in another way:
erl -sname gandalf@localhost
erl -sname bilbo@localhost
This time, you should finally get a "pong"(if you got "pang" before). The magic lies here, if start an erlang shell with "@localhost", and try "node()." you will get "gandalf@localhost". But if you start an erlang shell without "@localhost", you may get a different response when "node().", in may Ubuntu it is "gandalf@socrates-ubuntu-9". The reason are in /etc/hosts, in may Ubuntu there such two lines inside:
127.0.0.1 localhost
127.0.1.1 socrates-ubuntu-9
The second line defines a loop back domain other than localhost, and it guide the erlang shell to use it as default. Here we may comes to the distributed programming on two computers. Assume we have computers, one is "socrates-ubuntu-9" and the other is "socrates-ubuntu". On "socrates-ubuntu-9", we start an erlang shell "erl -sname gandalf", and on "socrates-ubuntu" we start an erlang shell "erl -sname bilbo". If "socrates-ubuntu-9" and "socrates-ubuntu" can find each other by domain names and we don't have a firewall issue, you may successfully get a "pong" in "socrates-ubuntu" by command:
netadm:ping( list_to_atom("gandalf@socrates-ubuntu-9")).
If no DNS available, a list of ip/name pair may be added to /etc/hosts of each computer.
Let's start with the classic example in Pragmatic Programming Erlang. First we start two erlang shell on the same machine, one named gandalf, the other named bilbo:
erl -sname gandalf
erl -sname bilbo
In node bilbo, you try "net_adm:ping(gandalf@localhost)." and you suppose to get a "pong" as response. Unfortunately, this may not happen on every computers, it is highly possible you may get a "pang" or some error massage. But you may start erlang shells in another way:
erl -sname gandalf@localhost
erl -sname bilbo@localhost
This time, you should finally get a "pong"(if you got "pang" before). The magic lies here, if start an erlang shell with "@localhost", and try "node()." you will get "gandalf@localhost". But if you start an erlang shell without "@localhost", you may get a different response when "node().", in may Ubuntu it is "gandalf@socrates-ubuntu-9". The reason are in /etc/hosts, in may Ubuntu there such two lines inside:
127.0.0.1 localhost
127.0.1.1 socrates-ubuntu-9
The second line defines a loop back domain other than localhost, and it guide the erlang shell to use it as default. Here we may comes to the distributed programming on two computers. Assume we have computers, one is "socrates-ubuntu-9" and the other is "socrates-ubuntu". On "socrates-ubuntu-9", we start an erlang shell "erl -sname gandalf", and on "socrates-ubuntu" we start an erlang shell "erl -sname bilbo". If "socrates-ubuntu-9" and "socrates-ubuntu" can find each other by domain names and we don't have a firewall issue, you may successfully get a "pong" in "socrates-ubuntu" by command:
netadm:ping( list_to_atom("gandalf@socrates-ubuntu-9")).
If no DNS available, a list of ip/name pair may be added to /etc/hosts of each computer.
Comments