net_adm:names/0
获取本地主机上 Erlang 节点的名字
用法:
names() -> {ok, [{Name, Port}]} | {error, Reason}
内部实现:
-spec names() -> {ok, [{Name, Port}]} | {error, Reason} when
Name :: string(),
Port :: non_neg_integer(),
Reason :: address | file:posix().
names() ->
names(localhost()).
-spec names(Host) -> {ok, [{Name, Port}]} | {error, Reason} when
Host :: atom() | string(),
Name :: string(),
Port :: non_neg_integer(),
Reason :: address | file:posix().
names(Hostname) ->
case inet:gethostbyname(Hostname) of
{ok, {hostent, _Name, _ , _Af, _Size, [Addr | _]}} ->
erl_epmd:names(Addr);
Else ->
Else
end.
返回一个以 {Name, Port} 的元组形式组成的本地主机上的 Erlang 节点列表信息,Name 是节点名,Port 是 Erlang 节点端口。
如果 epmd 没有运行,则返回 {error, address}。
net_adm:names().