[erlang-questions] Test code for global module does not work...

Andrew Stone <>
Fri Mar 12 04:49:14 CET 2010


You need to connect the nodes on the two computers. You can due this in multiple ways, one of them being net_kernel:connect_node/1. See http://erlang.org/doc/man/net_kernel.html for more info.

Also, You may want to read more about distributed erlang here:
http://www.erlang.org/doc/reference_manual/distributed.html

-Andrew



----- Original Message ----
From: 钱晓明 <>
To: 
Sent: Thu, March 11, 2010 10:27:36 PM
Subject: [erlang-questions] Test code for global module does not work...

Hi, I use global module to test global name, but it does not work. This is
the simple test code:

-module(testglobal).
-export([start_server/0, start_client/0, server/0]).

server()->
    receive
stop ->
     io:format("Stop server.~n", []);
hello ->
     io:format("Receive hello~n", []),
     server()
    end.

start_client()->
    global:send(gn_server, hello),
    global:send(gn_server, stop).
start_server()->
    global:register_name(gn_server, spawn(testglobal, server, [])).
Call start_server in one computer(winxp) first, then call start_client in
another computer(win2003) with same cookies. But start_client() failed with
error {badarg, {gn_server, hello}}. It looks like that the name is invalid.
So what is wrong in the code above?

By the way, the references say: *If Name is not a globally registered name,
the calling function will exit with reason {badarg, {Name, Msg}}. *So If I
want to process the failure rather than just exit with reason badarg, what
should I do ? Use try ... catch? I want to register new process with that
name when the send failed.



More information about the erlang-questions mailing list