Simple Distributed Erlang

大城市里の小女人 提交于 2019-12-11 00:40:19

问题


I've got a simple module:

-module(dist).
-compile([add/3]).
add(From,X,Y) ->
    From ! X+Y.

And I'm starting two nodes.

One with

erl -sname foo 

and another with

erl -sname bar

On the bar node I'm doing:

> c(dist).
{ok,dist}
> self().
<0.37.0>
> spawn('foo@unknown-00-23-6c-83-af-bd', dist, add, [self(), 3, 5]).

But the reponse I get is:

Error in process <0.48.0> on node 'foo@unknown-00-23-6c-83-af-bd' with exit value: {undef,[{dist,add,[<8965.37.0>,3,5]}]}

What does this error mean? I wondered if it meant that my foo node doesn't have this module defined? I didn't think it needed it, but the problem wasn't fixed by compiling dist in the foo node so I guess this isn't the problem.


回答1:


Export the add/3. Instead of a compile option.

-export([add/3]).



回答2:


if in the first node you use nl(module) then the beam of that module will be loaded to all connected nodes



来源:https://stackoverflow.com/questions/4199823/simple-distributed-erlang

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!