Skip to content

Instantly share code, notes, and snippets.

@kzk
Created April 27, 2010 16:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kzk/380979 to your computer and use it in GitHub Desktop.
Save kzk/380979 to your computer and use it in GitHub Desktop.
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