[erlang-questions] erlang-questions Digest, Vol 11, Issue 52

Vlad Dumitrescu <>
Thu Apr 17 16:03:50 CEST 2008


2008/4/17 wenew zhang <>:
> >>Wher you can specify in ServerName which node the server should be
> started.
> gen_server:start/start_link(ServerName,..) only have two options:
> {local,Name}| {global,GlobalName},
> in my project,
> i want communicate between two process cross nodes without use global
> option,
>  if can't do that,i think i must use a global mid- transfer the message
> like this:pid1---->global Server->pid2
>              Pid2---->global server ->Pid1
> but i think pid1->Pid2 more faster than above!

You need *some* kind of global server in any case, so that you can
tell process #1 about pid2 and process #2 about pid1. The good news is
that rpc:call uses the global 'rex' process and works nicely for this

So you have process#1 on node#1 with pid1 and process#2 on node#2 with pid2.

Write and load on node#1 a module with a function like
  set_pid(Pid) ->
     Pid1 = get_process1_pid(), %% implement this to get the right value
     Pid1 ! {peer, Pid},

>From node#2 call from process#2
  Pid1 = rpc:call('node#1', mymodule, set_pid, [Pid2]).

Process#1 should wait for a {peer, Pid} message before attempting to
talk to process#2.

This way, the processes get the other process' pid and can use it
directly. The method can be extended to several peers.

I hope this helps.
best regards,

More information about the erlang-questions mailing list