Jinterface addition

Vlad Dumitrescu XX (LN/EAB) vlad.xx.dumitrescu@REDACTED
Wed Mar 15 13:00:06 CET 2006


Hi,
 
Here is an addition to OtpEpmd.java, allowing programs to retrieve the
list of registered nodes.
 
best regards,
Vlad
 
    public static String[] lookupNames() throws IOException
    {
        Socket s = null;
 
        try
        {
            OtpOutputStream obuf = new OtpOutputStream();
            s = new Socket(InetAddress.getLocalHost(), epmdPort);
 
            obuf.write2BE(1);
            obuf.write1(names4req);
 
            // send request
            obuf.writeTo(s.getOutputStream());
 
            if (traceLevel >= traceThreshold)
                System.out.println("-> NAMES (r4) ");
 
            // get reply
            byte[] tmpbuf = new byte[1024];
            int n = s.getInputStream().read(tmpbuf);
 
            if (n < 0)
            {
                // this was an r3 node => not a failure (yet)
                if (s != null)
                    s.close();
                throw new IOException("Nameserver not responding when
requesting names");
            }
 
            OtpInputStream ibuf = new OtpInputStream(tmpbuf);
 
            int port = ibuf.read4BE();
            byte[] buf = new byte[n-4];
            System.arraycopy(tmpbuf, 4, buf, 0, n-4);
            String all = new String(buf);
            return all.split("\n");
            
        } catch (IOException e)
        {
            // epmd closed the connection = fail
            if (s != null)
                s.close();
            if (traceLevel >= traceThreshold)
                System.out.println("<- (no response)");
            throw new IOException("Nameserver not responding when
requesting names");
        } catch (OtpErlangDecodeException e)
        {
            if (s != null)
                s.close();
            if (traceLevel >= traceThreshold)
                System.out.println("<- (invalid response)");
            throw new IOException("Nameserver not responding when
requesting names");
        }
    }
 
 
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://erlang.org/pipermail/erlang-bugs/attachments/20060315/d0602366/attachment.htm>


More information about the erlang-bugs mailing list