`I still heart Erlang, but we're having some trouble communicating.  I'm trying to get RPCs to work correctly, but receive {Pid, Result} fails.  I'm pretty sure that it fails because I use {mbox, simpleserver@andLinux} as the initial Pid and JInterface responds with a differently named process id.  (Same process, but Erlang's representation.)<br>
<br>I can get it working through a hack (by returning {pid_result, mbox.whereis("mbox")} from the Java server on a {getpid} request), but is there a more elegant solution?<br><br>Thanks,<br><br>Steven<br><br>//<br>
<br>Client:<br><br>---<br>-module(client).<br>-export([echo/1, add/2, add2/2]).<br><br>rpc(Pid, Msg) -><br>    Pid ! {self(), Msg},<br>    receive<br>        {Pid, Result} -> {pid_received, Result};<br>        Result -> {nope, Result}<br>
    after 750 -> false<br>    end.<br><br>echo(Msg) -> rpc({mbox, simpleserver@andLinux}, {echo, Msg}).<br><br>add(X, Y) -> rpc({mbox, simpleserver@andLinux}, {add, X, Y}).<br><br>add2(X, Y) -> rpc({mbox, simpleserver@andLinux}, {add2, X, Y}).<br>
---<br><br>Server:<br><br>---<br>import com.ericsson.otp.erlang.*;<br><br>public class SimpleServer {<br>    public static void main(String[] args) throws Exception {<br>        OtpNode self = new OtpNode("simpleserver", "cookie");<br>
        OtpMbox mbox = self.createMbox("mbox");<br>        OtpErlangObject[] tupleElements = new OtpErlangObject[2];<br>        <br>        OtpEpmd.publishPort(self);<br>        tupleElements[0] = mbox.self();<br>
        <br>        while (true) try {<br>            OtpErlangTuple terms = (OtpErlangTuple) mbox.receive();<br>            OtpErlangPid from = (OtpErlangPid) terms.elementAt(0);<br>            OtpErlangTuple msg = (OtpErlangTuple) terms.elementAt(1);<br>
            <br>            String command = msg.elementAt(0).toString();<br>            <br>            if (command.equals("echo")) {<br>                mbox.send(from, new OtpErlangAtom(msg.elementAt(1).toString()));<br>
            }<br>            else if (command.equals("add")) {<br>                long x = ((OtpErlangLong) msg.elementAt(1)).longValue();<br>                long y = ((OtpErlangLong) msg.elementAt(2)).longValue();<br>
<br>                mbox.send(from, new OtpErlangLong(x+y));<br>            }<br>            else if (command.equals("add2")) {<br>                long x = ((OtpErlangLong) msg.elementAt(1)).longValue();<br>                long y = ((OtpErlangLong) msg.elementAt(2)).longValue();<br>
                tupleElements[1] = new OtpErlangLong(x+y);<br><br>                mbox.send(from, new OtpErlangTuple(tupleElements));<br>            }<br>        }<br>        catch (OtpErlangExit e) {<br>            break;<br>
        }<br>    }<br>}<br>---<br><br><br>