Test code for global module does not work...

钱晓明 <>
Fri Mar 12 04:27:36 CET 2010


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