Skip to content

Instantly share code, notes, and snippets.

@wanabe
Created June 4, 2014 23:59
Show Gist options
  • Select an option

  • Save wanabe/42ac45b15cbee047121d to your computer and use it in GitHub Desktop.

Select an option

Save wanabe/42ac45b15cbee047121d to your computer and use it in GitHub Desktop.
source "https://rubygems.org"
gem "msgpack-rpc"
require "msgpack/rpc"
class TestServer
def hello(a, b)
{"Var1" => "foo", "Var2" => "bar"}
end
end
server = MessagePack::RPC::Server.new
server.listen("0.0.0.0", 1985, TestServer.new)
server.run
import java.io.IOException;
import org.msgpack.MessagePack;
import org.msgpack.template.AbstractTemplate;
import org.msgpack.unpacker.Unpacker;
import org.msgpack.packer.Packer;
import org.msgpack.rpc.Client;
import org.msgpack.rpc.loop.EventLoop;
public class TestClient {
public static interface RPCInterface {
Named hello(String msg, int a);
}
public static class Named {
public int length;
public String toString() {
return "length:" + length;
}
}
public static class NamedTemplate extends AbstractTemplate<Named> {
public Named read(Unpacker u, Named to, boolean required) throws IOException{
if (to == null) {
to = new Named();
}
to.length = u.readMapBegin();
return to;
}
public void write(Packer pk, Named v, boolean required) throws IOException {}
}
public static void main(String[] args) throws Exception{
MessagePack msgpack = new MessagePack();
msgpack.register(Named.class, new NamedTemplate());
EventLoop loop = EventLoop.start(msgpack);
Client cli = new Client("localhost", 1985, loop);
RPCInterface iface = cli.proxy(RPCInterface.class);
System.out.println(iface.hello("hello", 1));
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment