[erlang-questions] global:registered_names() returns []

Andrew Stone <>
Wed Oct 22 22:19:40 CEST 2008


> It is odd how in books such as Programming Erlang by Joe and the videos by
> Kevin Smith never mention the need to use net_kernel:connect and somehow
> their examples seem to work. Maybe I missed something or my lack of
> experience cannot answer this odd scenario.

I just reviewed Joe's book and the reason his examples work are two-fold. His first examples with distributed erlang across nodes use the rpc:call mechanism which uses the well known REX process, so naming is unecessary. rpc:call handles node connections by itself. This took me a while to figure out a few months ago. His gen_server examples all use local naming so can only run within one node. He never states they should run across nodes. I haven't actually seen Kevin Smith's videos so can't comment there. I will say that you are on the right track and are off to a good start by using gen_server instead of hand rolled process loop servers. Learning OTP and how to use distributed Erlang takes time and sometimes it is hard to find the exact answer you are looking for. I've been on many newsgroups over the last few years and I must say that this one continues to impress me with the vast knowledge presented by list members and their willingness to help. So
 stick around here and keep experimenting and your knowledge base will surely grow.

> However, when I call gen_server:start_link for the first time, the name does
> not get registered! However any subsequent calls (without terminating the
> node) causes the process to register!!
  
I don't really understand this, maybe someone else can help.

> On top of that, when I call gen_server:call(account_monitor, getOnlineUsers)
> , I get the error:

> *exception exit: {noproc, {gen_server, call,[account_monitor,
> getOnlineUsers]}}

Since you are using global naming, you need to access your server's differently with gen_server:call

You need to do something like  gen_server:call({global,account_monitor}, getOnlineUsers).
Note that with this scenario you cannot register account_monitor globally on both nodes. If you would like to use the same process name register it locally and call like this gen_server:call({account,Node}, getOnlineUsers)

See http://erlang.org/doc/man/gen_server.html for details.

Good Luck,
Andrew



----- Original Message ----
From: Adrian Balij <>
To: Andrew Stone <>
Cc: 
Sent: Wednesday, October 22, 2008 3:48:01 PM
Subject: RE: [erlang-questions] global:registered_names() returns []

Thank you Andrew, that did work and I was able to see the registered names
on both nodes.

It is odd how in books such as Programming Erlang by Joe and the videos by
Kevin Smith never mention the need to use net_kernel:connect and somehow
their examples seem to work. Maybe I missed something or my lack of
experience cannot answer this odd scenario.

Although your solution worked, I ran into another problem. Both nodes can
see the registered names: [account_monitor]

However, when I call gen_server:start_link for the first time, the name does
not get registered! However any subsequent calls (without terminating the
node) causes the process to register!!

On top of that, when I call gen_server:call(account_monitor, getOnlineUsers)
, I get the error:

*exception exit: {noproc, {gen_server, call,[account_monitor,
getOnlineUsers]}}

Any have any ideas why?

Sincerely,

Adrian Balij
Software Engineer
Musket/Melburn Group


-----Original Message-----
From: Andrew Stone [mailto:] 
Sent: October 22, 2008 1:05 PM
To: 
Subject: Re: [erlang-questions] global:registered_names() returns []

Adrian,

I think you want to call net_kernel:connect right before you call
global:sync. That will actually connect the two nodes. Then global:sync will
synch the names on each node.

-Andrew



----- Original Message ----
From: "" <>
To: 
Sent: Tuesday, October 21, 2008 4:24:39 PM
Subject: [erlang-questions] global:registered_names() returns []

Hello everyone,

I am fairly new to Erlang and I have been trying to setup a gen_server so
that other nodes can communicate with it. However, on the client nodes,
every time I call global:registered_names(), it returns []. The odd thing
is on the server node, calling global:registered_names() returns
[account_monitor].

I am running two consoles on the same computer using the following commands:

erl -sname  -setcookie Test

erl -sname  -setcookie Test

Both consoles can ping each other.

My start function is:

% Initialize routine
start_link() -> gen_server:start_link({global, ?MODULE}, ?MODULE, [], []).

where ?MODULE = account_monitor.

I tried calling net_adm:world() and global:sync() and no luck at all!

The gen_server works fine (and by fine, I mean calling
gen_server:call(...)) when I start it locally (start_link({local, ?MODULE}
....).

Any help or suggestions would be extremely helpful at this point!

Additional info:
- OS: Leopard 10.5
- Erang bin: Sep 3, 2008

Thank you for your time,

Adrian Balij


_______________________________________________
erlang-questions mailing list

http://www.erlang.org/mailman/listinfo/erlang-questions



More information about the erlang-questions mailing list