Erlang/OTP Forums

Author Message

<  Erlang  ~  global:registered_names() returns []

abalij
Posted: Wed Oct 22, 2008 3:12 am Reply with quote
Joined: 22 Oct 2008 Posts: 2
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 a@localhost -setcookie Test

erl -sname b@localhost -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
- Erlang bin: Sep 3, 2008

Thank you for your time,

Adrian Balij
View user's profile Send private message
seanmc
Posted: Wed Oct 22, 2008 9:43 am Reply with quote
User Joined: 03 Aug 2007 Posts: 10
Hi Adrian,

You need toconnect the nodes with:
(b@localhost)2> net_kernel:connect_node(a@localhost).

//Sean.
View user's profile Send private message
abalij
Posted: Wed Oct 22, 2008 7:48 pm Reply with quote
Joined: 22 Oct 2008 Posts: 2
Thank you Sean, 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?
View user's profile Send private message
seanmc
Posted: Thu Oct 23, 2008 7:23 am Reply with quote
User Joined: 03 Aug 2007 Posts: 10
Hi Adrian,

I don't know what the problem is in your first question but to get your gen_server:call working you need to specify that it is registered globally:
gen_server:call({global,account_monitor}, getOnlineUsers)

//Sean.
View user's profile Send private message

Display posts from previous:  

All times are GMT
Page 1 of 1
This forum is locked: you cannot post, reply to, or edit topics.

Jump to:  

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You cannot download files in this forum