[英]how to change my hostname in erlang
這是我的kvs.erl:
-module(kvs).
-export([start/0, store/2, lookup/1]).
start() -> register(kvs, spawn(fun() -> loop() end)).
store(Key, Value) -> rpc({store, Key, Value}).
lookup(Key) -> rpc({lookup, Key}).
rpc(Q) ->
kvs ! {self(), Q},
receive
{kvs, Reply} ->
Reply
end.
loop() ->
receive
{From, {store, Key, Value}} ->
put(Key, {ok, Value}),
From ! {kvs, true},
loop();
{From, {lookup, Key}} ->
From ! {kvs, get(Key)},
loop()
end.
當我使用:erl -name zhao -setcookie abc啟動erlang時
然后:rpc:call(fifar @ huihua.sohu-inc.com,kvs,store,[weather,cold])。
它顯示錯誤:
(zhao@zjm1126.sohu-inc.com)1> rpc:call(fifar@huihua.sohu-inc.com,kvs,store,[weather,cold]).
** exception error: bad argument in an arithmetic expression
in operator -/2
called as 'fifar@huihua.sohu' - 'inc.com'
我認為這與linux主機名有關,
但是我使用這個linux shell:hostname -a
它不能顯示“ huihua.sohu-inc.com”
那我該怎么辦,
謝謝
查看錯誤說明,您發現二進制運算符“-”上有錯誤。 您只需要更改
(zhao@zjm1126.sohu-inc.com)1> rpc:call(fifar@huihua.sohu-inc.com,kvs,store,[weather,cold]).
至
(zhao@zjm1126.sohu-inc.com)1> rpc:call('fifar@huihua.sohu-inc.com',kvs,store,[weather,cold]).
這樣您就可以運行代碼。 二郎控制台看到fifar@huihua.sohu和inc.com為兩個不同的原子和看到fifar@huihua.sohu-inc.com作為兩個原子之間的差的操作 。 我建議您遵循erlang 參考手冊中的以下引用 :
原子是文字,是帶有名稱的常量。 如果原子不是以小寫字母開頭,或者包含字母數字字符,下划線(_)或@以外的其他字符,則應將其括在單引號(')中。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.