Thanks. I'll spend some time playing with the code to make sure I understand it.<br><br><div class="gmail_quote">On Fri, Jan 23, 2009 at 4:31 PM, Caoyuan <span dir="ltr"><<a href="mailto:dcaoyuan@gmail.com">dcaoyuan@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;"><div class="Ih2E3d"><a href="http://blogtrader.net/page/dcaoyuan/entry/rpc_server_for_erlang_in" target="_blank">http://blogtrader.net/page/dcaoyuan/entry/rpc_server_for_erlang_in</a><br>
<br>
2009/1/24 Steven Edwards <<a href="mailto:cureadvocate@gmail.com">cureadvocate@gmail.com</a>>:<br>
</div><div><div></div><div class="Wj3C7c">> `I still heart Erlang, but we're having some trouble communicating. I'm<br>
> trying to get RPCs to work correctly, but receive {Pid, Result} fails. I'm<br>
> pretty sure that it fails because I use {mbox, simpleserver@andLinux} as the<br>
> initial Pid and JInterface responds with a differently named process id.<br>
> (Same process, but Erlang's representation.)<br>
><br>
> I can get it working through a hack (by returning {pid_result,<br>
> mbox.whereis("mbox")} from the Java server on a {getpid} request), but is<br>
> 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<br>
> 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>
><br>
</div></div><div><div></div><div class="Wj3C7c">> _______________________________________________<br>
> erlang-questions mailing list<br>
> <a href="mailto:erlang-questions@erlang.org">erlang-questions@erlang.org</a><br>
> <a href="http://www.erlang.org/mailman/listinfo/erlang-questions" target="_blank">http://www.erlang.org/mailman/listinfo/erlang-questions</a><br>
><br>
</div></div></blockquote></div><br>