[erlang-questions] JInterface and node discovery

Vlad Dumitrescu vladdu55@REDACTED
Wed Dec 13 12:08:06 CET 2006


Hello,

On 12/13/06, Joost Yervante Damad <joost.damad@REDACTED> wrote:
>
> The problem I have is that almost all solutions to this "initial" problem
> require me to tell one of the parties the node name of the other party.
> However I'd rather have the JInterface node not know the other node and
> have
> the erlang node discover that the JInterface node is connected to the
> erlang
> cluster in a dynamic "triggered" way. One of the problem is that the
> JInterface node has no access to "globally registered" names. At least not
> without again first knowing the other node by name.
>

The version of jinterface used in the Erlide project (erlide.sf.net)
contains a method to query the epmd server for all the registered node
names.

The relevant code in the OtpEpmd class is (exception handling removed, code
is in
https://svn.sourceforge.net/svnroot/erlide/trunk/org.erlide.jinterface/src/com/ericsson/otp/erlang/OtpEpmd.java
):

    public static String[] lookupNames() throws IOException {
        Socket s = null;

        try {
            final OtpOutputStream obuf = new OtpOutputStream();
            s = new Socket(InetAddress.getLocalHost(), epmdPort);

            obuf.write2BE(1);
            obuf.write1(names4req);

            // send request
            obuf.writeTo(s.getOutputStream());

            // get reply
            final byte[] buffer = new byte[256];
            final ByteArrayOutputStream out = new
ByteArrayOutputStream(256);
            while (true) {
                final int bytesRead = s.getInputStream().read(buffer);
                if (bytesRead == -1) {
                    break;
                }
                out.write(buffer, 0, bytesRead);
            }

            final byte[] tmpbuf = out.toByteArray();
            final OtpInputStream ibuf = new OtpInputStream(tmpbuf);
            ibuf.read4BE(); // read port int
            // final int port = ibuf.read4BE();
            // check if port = epmdPort

            final int n = tmpbuf.length;
            final byte[] buf = new byte[n - 4];
            System.arraycopy(tmpbuf, 4, buf, 0, n - 4);
            final String all = new String(buf);
            return all.split("\n");

        } catch (final IOException e) {
        } catch (final OtpErlangDecodeException e) {
        }
    }


best regards,
Vlad
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-questions/attachments/20061213/52a13a24/attachment.htm>


More information about the erlang-questions mailing list