Introduction to Erlang Distributed (i)-ping pong
Test environments like http://willvvv.iteye.com/blog/1523918, 192.168.0.182 (centos-182) and 192.168.0.183 (centos-183),
1. Follow the link above (step 1-4) to set up a password-free login via ssh hostname.
2. Set the Magiccookie of Erlang, as the root account, the following commands are executed on both machines:
Cd/root
VI. Erlang.cookie
Input
Shell Code
- Centos_erlang
: Wq Exit Save
chmod Erlang.cookie,linux requires users to have read access to Magiccookie.
3. Start the EPMD process, it is responsible for mapping the symbol name to the machine address in two machines are executed: Epmd-daemon
4.ping-pong test code to derive from the online Erlang tutorial, Tut17.erl
Erlang Code
- -module (tut17).
- -export ([start_ping/1, start_pong/0, ping/2, pong/0]).
- Ping (0, Pong_node)
- {Pong, pong_node}! Finished,
- Io:format ("Ping Finished~n", []);
- Ping (N, Pong_node),
- {Pong, pong_node}! {ping, self ()},
- Receive
- Pong
- Io:format ("Ping received Pong~n", [])
- End
- Ping (N- 1, Pong_node).
- Pong ()
- Receive
- Finished
- Io:format ("Pong finished~n", []);
- {Ping, ping_pid}
- Io:format ("Pong received Ping~n", []),
- Ping_pid! Pong
- Pong ()
- End.
- Start_pong ()
- Register (Pong, spawn (tut17, Pong, [])).
- Start_ping (Pong_node)
- Spawn (tut17, Ping, [3, Pong_node]).
5. Execute erl-sname ' pong ' on centos-183, start the Pong node, enter Tut17:start_pong () after entering the ERL command line.
Perform erl-sname ' ping ' on centos-182, start the ping node, enter tut17:start_ping (' [email protected] ' after entering the ERL command line.
command and output see:
Note When you start the ping process on the ERL command line on the ping node, enter tut17:start_ping ([email protected]). The error will be as follows:
Shell Code
- * * Exception Error:bad argument in an arithmetic expression
- In operator-/2
- called as [email protected]- 183
In the reference to "Zhuang Zhou Dream Butterfly" http://www.blogjava.net/killme2008/archive/2007/06/15/124547.html When this error occurred, later on StackOverflow found a related problem Http://stackoverflow.com/questions/413736/naming-nodes-in-erlang was solved!
Introduction to Erlang Distributed (i)-ping pong