Created
April 27, 2010 16:58
-
-
Save kzk/380979 to your computer and use it in GitHub Desktop.
This file contains 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 '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