I have a simple server:
-module(simple_server).
-export([loop/0]).
loop() ->
receive
{fact, N, Sender} ->
Sender ! {factResult, fact(N), self()},
loop();
{fib, N, Sender} ->
Sender ! {fibResult, fib(N), self()},
loop();
{stop, Sender} ->
Sender ! ok
end.
fact(0) -> 1;
fact(N) -> N * fact(N - 1).
fib(N) -> fib(N, 1, 0).
fib(0, _B, A) -> A;
fib(N, B, A) -> fib(N-1, A+B, B).
Then I get this:
...\code>erl simple_server.erl
Eshell V5.7.5 (abort with ^G)
1> Server = spawn('server@myserver', fun simple_server:loop/0).
=ERROR REPORT==== 28-Jun-2010::10:46:29 ===
** Can not start erlang:apply,[#Fun<simple_server.loop.0>,[]] on server@myserver**
<0.33.0>
What did I miss?
It does not look like you have started as a distributed node. I get the same error message when my shell erlang node is started without a short name / long name using the “-sname” / “-name” flag of erl.
If you start this shell so it can participate in distribution you must also make sure the code for simple_server is loaded at the remote node, or that the remote node can autoload it from its code path.
For interactive use, you can use the
nc(File)ornl(Module)commands in the shell to load on all known nodes. Usenet_adm:ping(Node)to ping the node if it is not already listed when you doerlang:nodes().