[erlang-questions] How can i communicate with a gen_server-based server
Andreas Hillqvist
andreas.hillqvist@REDACTED
Fri Mar 28 09:41:56 CET 2008
Early guess, but dose not authserver:start_link() return {ok, PID}?.
Try:
{ok, Pid} = authserver:start_link().
Pid ! {213,'root','12345'}.
Kind regards
Andreas Hillqvist
2008/3/28, wenew zhang <wenewboy@REDACTED>:
> Dear All,
>
> i use gen_server behavior write a authserver
> code:
>
> -module(authserver).
>
> -behaviour(gen_server).
>
> %% gen_server callbacks
> -export([init/1, handle_call/3, handle_cast/2, handle_info/2, terminate/2,
> code_change/3]).
> -export([start_link/0]).
>
> -include("protocol.hrl").
> start_link() ->
> io:format("Authserver start_link~n"),
> gen_server:start_link({global, ?MODULE}, ?MODULE, [],[]).
>
>
> init([]) ->
> process_flag(trap_exit, true),
> io:format("Authserver init with []~n"),
> {ok,0}.
>
> handle_call(Request, _From, State) ->
> {stop, {unknown_call, Request}, State}.
>
>
> handle_cast(_Msg, State) ->
> {noreply, State}.
>
>
>
> handle_info({?PLLOGIN,Uid,Pwd},State) ->
> io:format("PLLogin id:~w Uid:~w Pwd:~w~n",[?PLLOGIN,Uid,Pwd]).
>
> terminate(_Reason, _N) ->
> ok.
>
>
> code_change(_OldVsn, State, _Extra) ->
> {ok, State}.
>
> %%___________________end_________________________
>
>
>
> handle_info({?PLLOGIN,Uid,Pwd},State) ->
> io:format("PLLogin id:~w Uid:~w Pwd:~w~n",[?PLLOGIN,Uid,Pwd]).
>
> i want call this function above, send ?PLLOGIN},[Uid,Pwd]) from other node,
> and then,authserver send some message back ,
> i try:
> 2> Pid=authserver:start_link().
> Authserver start_link
> Authserver init with []
> {ok,<0.32.0>}
> 3> Pid!{213,'root','12345'}.
> ** exception error: bad argument
> in operator !/2
> called as {ok,<0.32.0>} ! {213,root,'12345'}
> 4>
>
> what can i do?
> _______________________________________________
> erlang-questions mailing list
> erlang-questions@REDACTED
> http://www.erlang.org/mailman/listinfo/erlang-questions
>
More information about the erlang-questions
mailing list