この記事を見た後、私はmochiwebをいじくり回しています。記事で行われていることを複製しようとしている間-基本的にmochiwebサーバーをセットアップし、2つのerlangノードを持ち、次に一方のノードで定義された関数をもう一方のノードで呼び出します(2つのノード間でnet_adm:ping()を設定した後、それぞれを認識します他の)。
その関数呼び出し部分まで、すべてを追跡することができました。mochiwebサーバーであるn1@localhostで、(記事で行ったように)次のように呼び出します。
router:login(IdInt, self()).
次に、router.erlスクリプトであるn2 @ localhostで、ログイン関数を定義しました。
login(Id, Pid) when is_pid(Pid) ->
gen_server:call(?SERVER, {login, Id, Pid}).
handle_call({login, Id, Pid}, _From, State) when is_pid(Pid) ->
ets:insert(State#state.pid2id, {Pid, Id}),
ets:insert(State#state.id2pid, {Id, Pid}),
link(Pid), % tell us if they exit, so we can log them out
io:format("~w logged in as ~w\n",[Pid, Id]),
{reply, ok, State};
コードの関連部分のみを貼り付けました。ただし、ブラウザでWebサーバーにアクセスすると、n1@localhostで次のエラーレポートが表示されます。
=CRASH REPORT==== 11-Jun-2009::12:39:49 ===
crasher:
initial call: mochiweb_socket_server:acceptor_loop/1
pid: <0.62.0>
registered_name: []
exception error: undefined function router:login/2
in function mochiconntest_web:loop/2
in call from mochiweb_http:headers/5
ancestors: [mochiconntest_web,mochiconntest_sup,<0.59.0>]
messages: []
links: [<0.61.0>,#Port<0.897>]
dictionary: [{mochiweb_request_path,"/test/123"}]
trap_exit: false
status: running
heap_size: 1597
stack_size: 24
reductions: 1551
neighbours:
=ERROR REPORT==== 11-Jun-2009::12:39:49 ===
{mochiweb_socket_server,235,{child_error,undef}}
グーグルした後、エラーが何を言おうとしているのかについての基本的な要点を理解しました-基本的にはn1 @localhostで呼び出されているログイン関数は定義されていません-しかしそれはn2@ localhostで定義されています(そして両方のノードはそれぞれを知っていますその他-nodes().確認しました)!! どこが悪いのか教えてください!