简体   繁体   中英

how to change my hostname in erlang

this is my 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.

when i startup erlang using :erl -name zhao -setcookie abc

and then : rpc:call(fifar@huihua.sohu-inc.com,kvs,store,[weather,cold]).

it show error:

(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'

i think it is about linux hostname ,

but i use this linux shell : hostname -a

it cant show "huihua.sohu-inc.com"

so what can i do ,

thanks

Looking at the error description you have an error on the binary operator "-". you would only require to change the

(zhao@zjm1126.sohu-inc.com)1> rpc:call(fifar@huihua.sohu-inc.com,kvs,store,[weather,cold]).

to

(zhao@zjm1126.sohu-inc.com)1> rpc:call('fifar@huihua.sohu-inc.com',kvs,store,[weather,cold]).

And you will get your code running. Erlang console is seeing fifar@huihua.sohu and inc.com as two distinct atoms and seeing fifar@huihua.sohu-inc.com as a difference operation between two atoms . I advice you to follow this quote from erlang reference manual :

An atom is a literal, a constant with name. An atom should be enclosed in single quotes (') if it does not begin with a lower-case letter or if it contains other characters than alphanumeric characters, underscore (_), or @.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM