Introduction to Erlang Distributed (i)-ping pong

Source: Internet
Author: User

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
    1. 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
  1. -module (tut17).
  2. -export ([start_ping/1, start_pong/0, ping/2, pong/0]).
  3. Ping (0, Pong_node)
  4. {Pong, pong_node}! Finished,
  5. Io:format ("Ping Finished~n", []);
  6. Ping (N, Pong_node),
  7. {Pong, pong_node}! {ping, self ()},
  8. Receive
  9. Pong
  10. Io:format ("Ping received Pong~n", [])
  11. End
  12. Ping (N- 1, Pong_node).
  13. Pong ()
  14. Receive
  15. Finished
  16. Io:format ("Pong finished~n", []);
  17. {Ping, ping_pid}
  18. Io:format ("Pong received Ping~n", []),
  19. Ping_pid! Pong
  20. Pong ()
  21. End.
  22. Start_pong ()
  23. Register (Pong, spawn (tut17, Pong, [])).
  24. Start_ping (Pong_node)
  25. 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
    1. * * Exception Error:bad argument in an arithmetic expression
    2. In operator-/2
    3. 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.