[erlang-questions] gen_server and the ! operator

Magnus Henoch magnus@REDACTED
Wed Apr 15 11:39:45 CEST 2009


ulf_A <uaforum1@REDACTED> writes:

> Hello,
>
> i have a understanding problem with otp gen_server and the ! (send)
> operator.
>
> In my small test programm, i use the "normal" way to use the gen_server
> behavior.

How does your start_link function look?  Maybe like this:

start_link(Name) ->
    gen_server:start_link({local, Name}, ?MODULE, [], []).

If so, you can run myServer:start_link(foo) to have the server register
itself as 'foo'.  (More likely, you would put ?MODULE instead of Name,
to always use the same name as the module.)

> I want to do is this:
>
> whereis(myServer) ! {Id}.

If you have done the above, you just write:

foo ! {Id}.

The server's handle_info function will then be called:

handle_info({Id}, State) ->
    io:format("got id message: ~p~n", [Id]),
    {noreply, State}.

Hope that helps,
-- 
Magnus Henoch, magnus@REDACTED
Erlang Training and Consulting
http://www.erlang-consulting.com/




More information about the erlang-questions mailing list