简体   繁体   English

如何连接到已注册的节点(Erlang)并从另一个erlang应用程序使用它

[英]How to connect to a registered Node (Erlang) and use it from another erlang application

I have a node started on 我有一个节点开始于

erl -name n1@198.XXX.X.XX -setcookie somecookie erl -name n1@198.XXX.X.XX -setcookie somecookie

(n1@198.XXX.X.XX)> (n1@198.XXX.X.XX)>

but then I have another erlang application in which I have a module where I want to use the node that I have just registered (n1@198.XXX.X.XX). 但是然后我有了另一个erlang应用程序,其中有一个模块,我要在其中使用我刚刚注册的节点(n1@198.XXX.X.XX)。 I tried to do do directly from code net_adm:ping(n1@198.XXX.X.XX). 我试图直接从代码net_adm:ping(n1@198.XXX.X.XX)做。 and I get a pang. 我感到很困惑 I can see that net_adm:names(). 我可以看到net_adm:names()。 returns in the tuple all the registered and living nodes.{ok [{node, 999}],[{n1,9993}],[{theappnode, 8383}]} 返回元组中所有已注册和活动的节点。{ok [{node,999}],[{n1,9993}],[{theappnode,8383}]}

I need a way to connect to n1, and then use to to ping another remote node with rpc, something like 我需要一种连接到n1的方法,然后使用rpc对另一个远程节点执行ping操作,例如

conn = connect to node (n1) and then do the rpc... these all from the module code of another erlang application.... Is the above possible? conn =连接到节点(n1),然后进行rpc ...所有这些都来自另一个erlang应用程序的模块代码。...以上可能吗?

Possibly your other node wasn't started with the same cookie. 可能您的其他节点不是以相同的cookie开头的。 You have two solutions: 您有两种解决方案:

  1. Start the other node with the same cookie 使用相同的cookie启动另一个节点

     erl -name otherapp -setcookie some cookie 1> net_adm:ping('n1@198.XXX'). pong 
  2. Start the other node and tell it what is the cookie of the n1 node. 启动另一个节点,并告诉它n1节点的cookie是什么。

     erl -name otherapp 1> net_adm:ping('n1@198.XXX'). pang 2> erlang:set_cookie('n1@198.XXX', 'somecookie'). true 3> net_adm:ping('n1@198.XXX'). pong 

You cannot mix short names and long names (-sname and -name) in a distributed cluster. 您不能在分布式集群中混合短名称和长名称(-sname和-name)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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