【问题标题】:how to change my hostname in erlang如何在erlang中更改我的主机名
【发布时间】:2011-12-09 03:31:31
【问题描述】:

这是我的 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:主机名 -a

无法显示“huihua.sohu-inc.com”

那我该怎么办,

谢谢

【问题讨论】:

    标签: linux erlang rpc hostname


    【解决方案1】:

    查看错误描述,二元运算符“-”有错误。您只需要更改

    (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]).
    

    您将让您的代码运行。 Erlang 控制台将 fifar@huihua.sohu 和 inc.com 视为两个不同的原子,并将 fifar@huihua.sohu-inc.com 视为两个原子之间的差分运算。我建议你遵循 erlang reference manual 的这句话:

    原子是一个字面量,一个有名字的常数。如果原子不是以小写字母开头或包含除字母数字字符、下划线 (_) 或 @ 以外的其他字符,则原子应括在单引号 (') 中。

    【讨论】:

      猜你喜欢
      • 2017-08-11
      • 2020-10-20
      • 2021-03-24
      • 2014-03-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多