[erlang-questions] How can i communicate with a gen_server-based server

Christian S chsu79@REDACTED
Fri Mar 28 09:36:58 CET 2008

On Fri, Mar 28, 2008 at 9:16 AM, wenew zhang <wenewboy@REDACTED> wrote:
> Dear All,
>  handle_call(Request, _From, State) ->
>     {stop, {unknown_call, Request}, State}.

I suggest that you use the handle_call-feature of the gen_server behavior.

handle_call({authenticate, Login, Password}, _From, State) ->
   {reply, lookup_user(Login, Password), State};
handle_call(Request, _From, State) ->
   {stop, {unknown_call, Request}, State}.

You are registering your gen_server globally as ?MODULE, that is, the
name of the module: 'authserver'.

That registering means that you should be able to call
gen_server:call(authserver, {authenticate, Login, Password}) from any
node. Using gen_server:call/3 you can also give this call a timeout.

>  3> Pid!{213,'root','12345'}.
>  ** exception error: bad argument
>      in operator  !/2
>         called as {ok,<0.32.0>} ! {213,root,'12345'}

The error message is letting you know that in "Pid ! {213, root,
'12345'}" the value of Pid is {ok, <process id>}.

This means you should have written {ok, Pid} = authserver:start_link().

But as you register the gen_server process as 'authserver', you dont
really need the Pid.

More information about the erlang-questions mailing list