代码之家  ›  专栏  ›  技术社区  ›  Paralife

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

  •  3
  • Paralife  · 技术社区  · 15 年前

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

    2 回复  |  直到 15 年前
        1
  •  2
  •   Zed    15 年前

    它是作为“-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();
        }
    
    }
    

    erl -sname shell@localhost -setcookie zed
    
    (shell@localhost)1> net_adm:ping(javambox@localhost).
    pong
    (shell@localhost)2> {mbox, javambox@localhost} ! hello. 
    hello
    
        2
  •  1
  •   Vlad Dumitrescu    15 年前

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

    推荐文章