未定義功能看到this article後,我一直在擺弄了Mochiweb。在嘗試複製文章中的內容時 - 基本上設置了一個mochiweb服務器,有兩個erlang節點,然後調用另一個節點中定義的函數(在兩個節點之間設置net_adm:ping()後,他們知道每個節點其他)。異常錯誤:到Mochiweb /二郎
我能夠關注一切,直到該函數調用部分。在N1 @ localhost,它是在受Mochiweb服務器,我叫(就像在文章中進行):
router:login(IdInt, self()).
,然後在N2 @ localhost,它是在router.erl劇本,我已經定義登錄功能:
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 @本地這個錯誤報告:
=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}}
周圍的Googling後,我得到了什麼樣的錯誤是想說一個基本精神 - 基本上它說在n1 @ localhost中調用的登錄函數沒有定義 - 但是它在n2 @ localhost中定義(並且兩個節點彼此瞭解 - 我做了nodes().
檢查)!請告訴我我哪裏出錯了!
這是否意味着我只需要在mochiweb/erl腳本(和聲明-export([login/2])中獲得上述兩行)。 當我這樣做,我得到「未定義的宏」'服務器''「錯誤。如果我使用「%-behaviour(gen_server)」,那麼我必須重寫默認功能。 – thomas55 2009-06-12 02:03:34
或者我缺少其他明顯的東西?我是否需要將router.erl放置在與mochiweb腳本相同的文件夾中?當然,我不是那樣做的... – thomas55 2009-06-12 02:05:50