Initializing Name / Alias ​​Name Jinterface OtpNode

When creating an OtpNode instance, what type of node is it? Is it like erl -sname xxx or like elr-name xxx?

+3
source share
2 answers

It works like "-sname". At least according to the following example.

TryOTP.java (import is not used specifically)

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();
    }

}

Launching the 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
+2
source

From Java code, you can connect to Erlang hosts running with the names -name and -sname. Only in the other direction is it difficult (and I have no answer to this). Therefore, if you can make the connection from the Java side, the problem will be solved.

+1
source

Source: https://habr.com/ru/post/1720544/


All Articles