Beginner OTP question

Vance Shipley vances@REDACTED
Fri Feb 18 06:18:51 CET 2005


Bill,

}      gen_server:start({global, myserver}, myserver, [], []).
                        ^^^^^^^^^^^^^^^^^
Global is not the normal way to register a process, it uses the
global module.  This is an entirely different registry than what
is used locally for the processes on a node.  You could send to
it, from either the local or remote nodes, with one of these:

(gbye@REDACTED)1> global:send(myserver, "Hello there!").
(gbye@REDACTED)2> global:whereis_name(myserver) ! "Hello there!".

Registering it with the global module does not also register it
with the normal registry locally.

(hello@REDACTED)1> global:register_name(myserver, self()).
(hello@REDACTED)2> myserver ! "Hello there!".

=ERROR REPORT==== 18-Feb-2005::05:03:11 ===
Error in process <0.45.0> on node 'hello@REDACTED' with exit value: {badarg,...


The syntax you tried to use is actually how you address a process known 
to be registered locally at a remote node (correcting the syntax):

(gbye@REDACTED)2> {myserver, 'hello@REDACTED'} ! send.

Now this wasn't going to work anyway.  In your gen_server you have a
handle_call/3 callback function expecting a 'send'.  The handle_call/3
callback is called when a client calls gen_server:call/2.  So what you
wanted to do was:

(hello@REDACTED)3> gen_server:call({global, myserver}, send).

If you had wanted to use a normal send instead of the synchronous
call then you would use the handle_info/2 callback function as that
is where it will be handled.  You won't be able to reply though.

}  send() ->
}      gen_server:call(myserver, send).

So change your interface function to;

send() ->
	gen_server:call({global, myserver}, send).

And you can use it as (assuming the server code is loaded):

(gbye@REDACTED)3> myserver:send().


	-Vance




More information about the erlang-questions mailing list