Ruby :编写一个 XML-RPC 程序

清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>

require 'xmlrpc/server'

server = XMLRPC::Server.new(1234)
server.add_handler("sample.sumAndDifference") do |a,b|
  { "sum" => a.to_i + b.to_i,
    "difference" => a.to_i - b.to_i }
end

trap("INT") { server.shutdown }
server.serve

# The following client could use the sample.sumAndDifference method 
# made available by the preceding server:
require 'xmlrpc/client'

server = XMLRPC::Client.new2("http://127.0.0.1:1234/")
puts server.call("sample.sumAndDifference", 5, 3).inspect