zjm*_*126 2 linux erlang rpc hostname
这是我的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.
Run Code Online (Sandbox Code Playgroud)
当我启动erlang时使用:erl -name zhao -setcookie abc
然后: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'
Run Code Online (Sandbox Code Playgroud)
我认为这是关于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]).
Run Code Online (Sandbox Code Playgroud)
至
(zhao@zjm1126.sohu-inc.com)1> rpc:call('fifar@huihua.sohu-inc.com',kvs,store,[weather,cold]).
Run Code Online (Sandbox Code Playgroud)
并且您将运行您的代码.二郎控制台看到fifar@huihua.sohu和inc.com为两个不同的原子和看到fifar@huihua.sohu-inc.com作为两个原子之间的差分运算.我建议你按照erlang 参考手册中的引用:
原子是文字,是名称的常量.如果原子不以小写字母开头,或者如果它包含除字母数字字符,下划线(_)或@之外的其他字符,则应将原子括在单引号(')中.