A simple solution came to mind: if receive {Pid, Result} isn't working because Pid is bound to {mbox, simpleserver@andLinux}, why not return that instead of mbox.self()? Unsurprisingly, it works!<br><br>The updated server code:<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> OtpErlangObject[] selfTuple = new OtpErlangObject[2];<br> selfTuple[0] = new OtpErlangAtom("mbox");<br>
selfTuple[1] = new OtpErlangAtom(self.node());<br> <br> OtpEpmd.publishPort(self);<br> tupleElements[0] = new OtpErlangTuple(selfTuple);<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><div class="gmail_quote">On Fri, Jan 23, 2009 at 3:09 PM, Steven Edwards <span dir="ltr"><<a href="mailto:cureadvocate@gmail.com">cureadvocate@gmail.com</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="border-left: 1px solid rgb(204, 204, 204); margin: 0pt 0pt 0pt 0.8ex; padding-left: 1ex;">`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</blockquote>
</div><br>