Jinterface addition

Raimo Niskanen <>
Thu Mar 23 15:32:02 CET 2006


Thank you for the patch.

We will have a look at it. It is not certain it will make it into
R11B, though...



 (Vlad Dumitrescu XX LN/EAB) writes:

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

-- 

/ Raimo Niskanen, Erlang/OTP, Ericsson AB



More information about the erlang-bugs mailing list