Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
require 'rubygems'
require 'msgpack'
require 'msgpack/rpc'
class CustomData
attr_accessor :a
attr_accessor :b
def initialize(a, b)
@a = a
@b = b
end
def to_msgpack(o = '')
[@a, @b].to_msgpack(o)
end
def self.from_msgpack(obj)
CustomData.new(obj[0], obj[1])
end
end
class Server
def func(d)
p CustomData.from_msgpack(d)
end
end
if ARGV.empty?
puts "test.rb <serv|cln>"
exit
end
t = ARGV.shift
if t == "serv"
port = 1985
gossiper = Server.new
serv = MessagePack::RPC::Server.new
serv.listen("0.0.0.0", port, gossiper)
serv.run
else
d = CustomData.new(1, 2)
cli = MessagePack::RPC::Client.new("127.0.0.1", 1985)
cli.timeout = 5
cli.call(:func, d)
cli.close
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment