[erlang-questions] Newbie question - how do I get global:register_name() to work?

Ludovic Coquelle lcoquelle@REDACTED
Wed Sep 19 03:26:55 CEST 2007

I just tested it, and it seems to work one my local machine.
Maybe you omited to "kind of connect" the nodes (help then to discover each
others) using net_adm:ping/1 for example?

Following is my test with output of the 2 VM.

erl -sname e1
Erlang (BEAM) emulator version 5.5.4 [source] [async-threads:0] [hipe]
Eshell V5.5.4  (abort with ^G)
(e1@REDACTED)1> P1 = spawn(fun() -> receive _ -> ok end end).
(e1@REDACTED)2> global:register_name(test, P1).
(e1@REDACTED)3> global:registered_names().
(e1@REDACTED)4> global:whereis_name(test).

erl -sname e2
Erlang (BEAM) emulator version 5.5.4 [source] [async-threads:0] [hipe]
Eshell V5.5.4  (abort with ^G)
(e2@REDACTED)1> net_adm:ping(e1@REDACTED).
(e2@REDACTED)2> global:registered_names().
(e2@REDACTED)3> global:whereis_name(test).

On 9/19/07, G Bulmer <gbulmer@REDACTED> wrote:
> I apologise for this newbie question, but ...
> Would someone please explain how to get global:register_name()/
> global:whereis_name() to work across nodes?
> I have some very simple, experimental, local-registry based code
> which looks roughly like this:
> register(lookup, spawn(fun() -> some_fun() end)),
> and uses this message sending syntax from the 'remote' machine:
> { lookup, 'server@REDACTED' } ! { some_message }
> This code works okay across nodes on the same machine, and nodes on
> two machines; so cookie, -name server, etc. seem to be fine.
> I've tried converting it to use global:register_name(...), etc:
> Status = global:register_name(lookup, Pid = spawn(fun() -> some_fun()
> end))
> This returns 'yes' as the value of Status, and seems to work within
> the VM that calls global:register_name(), i.e. global:whereis_name
> (lookup) returns the same pid value as bound to Pid in register_name,
> and global:registered_names() returns [lookup].
> BUT in a second VM, on the same machine it fails (the 2nd VM is
> started with erl -name client). Specifically:
> global:whereis_name(lookup)   returns 'undefined', and
> global: registered_names()   returns [].
> I can see the process global_name_server mentioned in the global:
> module doc, in response to i() to the shell:
> <0.11.0>              global:init/1
> 233       69    0
> global_name_server    gen_server:loop/6                       12
> What am I missing?
> Help and advice would be much appreciated.
> Garry
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20070919/aefe08c0/attachment.htm>

More information about the erlang-questions mailing list