3

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

4

2 回答 2

2

它作为“-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
于 2009-10-20T16:42:25.473 回答
1

从 Java 代码中,您可以连接到以 -name 和 -sname 开头的 Erlang 节点。只是在另一个方向上它很棘手(我没有答案)。因此,如果您可以从 Java 端进行连接,那么问题就解决了。

于 2009-11-17T09:57:07.300 回答