Created
June 4, 2014 23:59
-
-
Save wanabe/42ac45b15cbee047121d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| source "https://rubygems.org" | |
| gem "msgpack-rpc" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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