如果生成在单独的 Eshell 上,客户端和服务器不通信?

Client and server don't communicate if spawned on separate Eshell?

我有这两个 Erlang 模块:

服务器:

-module(server).

-export([start/0, loop/0]).

books(Cc) ->
  string:concat("Works ", Cc).

loans(Name) ->
  string:concat("Works too ", Name).

loop() ->
  receive
    {ClientPID, books, Info} ->
      ClientPID ! books(Info),
      loop();
    {ClientPID, loans, Info} ->
      ClientPID ! loans(Info),
      loop();
    _ ->
      io:fwrite("Invalid request received!~n"),
      loop()
  end.


start() ->
  spawn(server, loop, []).

和客户:

-module(client).

-export([start/1, client/1]).

start(Server_Address) ->
  spawn(client, client, [Server_Address]).

client(Server_Address) ->
  Server_Address ! {self(), books, "potato"},
  receive
    Response ->
      io:format("CLIENT ~w: ~w~n", [self(), Response])
  end.

我调用 Pid = server:start() 它给我一个正确的 Pid,没有任何错误,但是当我调用 client:start(Pid) 或 client:client(Pid) 时不同的Eshell它只是不通信(如果在同一个Eshell中调用它可以工作,显然)。

我知道我只是做错了什么,但那是什么? 谢谢

很可能两个节点都没有集群,您可以使用 nodes()

检查哪些节点属于集群

为了启动可到达的节点,您必须将它们命名为:

erl -sname client@localhost

并 ping 另一个节点:

$> erl -sname server@localhost                   
Erlang/OTP 23 [erts-11.1] [source] [64-bit] [smp:4:4] [ds:4:4:10] [async-threads:1]

Eshell V11.1  (abort with ^G)
(server@localhost)1> nodes().
[]
(server@localhost)2> net_adm:ping('client@localhost').
pong
(server@localhost)3> nodes().                         
[client@localhost]