[erlang-questions] How to call a locally Pid cross node on Distributed Application!
Andreas Hillqvist
andreas.hillqvist@REDACTED
Thu Apr 17 11:53:55 CEST 2008
Now you create two processes on the node. A process that starts the gen_server.
You should use gen_server:start_link/4:
start_link(ServerName, Module, Args, Options)
and/or gen_server:start/4:
start(ServerName, Module, Args, Options)
Wher you can specify in ServerName which node the server should be started.
If you still want to start the server on the node by spawning a
process, I guess you will have to somhow return the PID (Is a PID
local?) from the proess you spawned.
Because the spawn/4 you use:
Pid=spawn(authservernode@REDACTED,authserver1,start,[]).
Returns the spawnde processs. It dose not return the PID to the
gen_server it starts.
Kind regards
Andreas Hillqvist
2008/4/17, wenew zhang <wenewboy@REDACTED>:
> the source code as below,on the first time start the two nodes,i get output
> like this:
> (socketservernode@REDACTED)2>
> spawn(authservernode@REDACTED,authserver1,start,[]).
> <5869.52.0>
> Authserver start
> Authserver init with []
>
> and then i start i again,
> (socketservernode@REDACTED)3>
> Pid=spawn(authservernode@REDACTED,authserver1,start,[]).
> Authserver start
> <5869.54.0>
>
> No" Authserver init with [] " output on the Init parts,
> on the terminate: io:format("Terminating...~n"),
> can't find this output,
> i use rb nether find log-message on the socketservernode no authservernode
>
> Best Regards
>
> Wenew Zhang
> %%%%%%%%%%%%Begin%%%%%%%%%%%%%%%%%%%%
>
> -module(authserver1).
>
> -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,start/0]).
>
> start_link() ->
> io:format("Authserver start_link~n"),
> gen_server:start_link({global, ?MODULE}, ?MODULE, [],[]).
>
> start() ->
> io:format("Authserver start~n"),
> gen_server:start({global, ?MODULE}, ?MODULE, [],[]).
>
> init([]) ->
> process_flag(trap_exit, true),
> io:format("Authserver init with []~n"),
> {ok,0}.
>
>
>
> handle_call({213,Uid,Pwd},_From,State) ->
> io:format("PLLogin id:~w Uid:~w Pwd:~w~n",[213,Uid,Pwd]),
> {reply,213, State}.
>
> handle_cast(_Msg, State) ->
> {noreply, State}.
>
> handle_info({213,Uid,Pwd},State) ->
> io:format("PLLogin id:~w Uid:~w Pwd:~w~n",[213,Uid,Pwd]),
> {noreply, State}.
>
> terminate(_Reason, _N) ->
> io:format("Terminating...~n"),
> ok.
>
>
> code_change(_OldVsn, State, _Extra) ->
> {ok, State}.
> %%%%%%%%%%The end%%%%%%%%%%%%%%%%%%%
>
>
>
> 2008/4/17, Andreas Hillqvist <andreas.hillqvist@REDACTED>:
> > It sounds like the process of the PID has died.
> > How do you start your gen_server?
> >
> >
> > Kind regars
> > Andreas Hillqvist
> >
> > 2008/4/17, wenew zhang <wenewboy@REDACTED>:
> >
> > > Yes,it's could create a process and use Pid!{Message} send message,
> > >
> > > but i use gen_server behavior so i want to use
> > > gen_server:call(Pid,{Message}) to send message,
> > >
> > > in my situation, create process successfully,but can't use
> gen_server:call()
> > >
> > > 1.why i get the "exception exit: {noproc," message like below?
> > > 2.when i use appmon:start() ,i neither find the pid on AuthserverNode
> nor
> > > SocketServerNode.
> > >
> > >
> > >
> > > (socketservernode@REDACTED)4>
> > >
> Pid=spawn(authservernode@REDACTED,authserver1,start,[]).
> > > <5805.82.0>
> > > Authserver start_link
> > > (socketservernode@REDACTED)5> Pid.
> > > <5805.82.0>
> > > (socketservernode@REDACTED)6>
> > > gen_server:call(Pid,{213,"root","123456"}).
> > > ** exception exit: {noproc,
> > >
> > > {gen_server,call,[<5805.82.0>,{213,"root","123456"}]}}
> > > in function gen_server:call/2
> > >
> > >
> > >
> > >
> > > >
> > > >
> > > > > thanks for your reply,
> > > > > i see a example like you said on Joe 's book,
> > > > > can i use gen_server as a rpc:call()'s Arg ?How can i do that?
> > > > > tks
> > > >
> > > >
> > > > Sure you can.
> > > >
> > > > rpc:call(Node, yourgenserver, start, [Params]).
> > > >
> > > >
> > > > BTW don't top-post and don't forget to CC to erlang-questions :)
> > > >
> > > > --
> > > > With best regards!
> > > >
> > >
> > >
> >
> > > _______________________________________________
> > > erlang-questions mailing list
> > > erlang-questions@REDACTED
> > > http://www.erlang.org/mailman/listinfo/erlang-questions
> > >
> >
>
>
More information about the erlang-questions
mailing list