gpt4 book ai didi

erlang - Jinterface OtpNode初始化-name或-sname标志

转载 作者:行者123 更新时间:2023-12-01 15:18:16 25 4
gpt4 key购买 nike

在创建 OtpNode 实例时,这是什么类型的节点?它是像 erl -sname xxx 还是像 elr -name xxx ?

最佳答案

它以“-sname”的形式工作。至少根据下面的例子。

TryOTP.java(故意省略导入)

public class TryOTP {
public void start() {
OtpNode node = null;

try {
node = new OtpNode("javambox@localhost", "zed"); // name, cookie
} catch (IOException ex) {
System.exit(-1);
}

System.out.println("Connected to epmd...");

if (node.ping("shell@localhost", 2000)) {
System.out.println("shell@localhost is up.");
} else {
System.out.println("shell@localhost is down");
}

OtpMbox mbox = node.createMbox("mbox");

while (true) {

OtpErlangObject o = null;
try {
o = mbox.receive();
} catch (OtpErlangDecodeException ex) {
System.out.println("Received message could not be decoded: " + ex);
continue;
} catch (OtpErlangExit ex) {
System.out.println("Remote pid " + ex.pid() + " has terminated.");
continue;
}
System.out.println("Received: " + o);
}
}

public static void main(String[] args)
{
System.getProperties().setProperty("OtpConnection.trace", "3");
new TryOTP().start();
}

}

运行 Erlang shell:

erl -sname shell@localhost -setcookie zed

(shell@localhost)1> net_adm:ping(javambox@localhost).
pong
(shell@localhost)2> {mbox, javambox@localhost} ! hello.
hello

关于erlang - Jinterface OtpNode初始化-name或-sname标志,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1592943/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com