server.rb
#encoding:utf-8
#! /usr/bin/env ruby
require "xmlrpc/server"
#s = XMLRPC::CGIServer.new
s = XMLRPC::Server.new(8080)
s.add_handler("sample.sumAndDifference") do |a,b|
{ "sum" => a + b, "difference" => a - b }
end
s.serve
#require "xmlrpc/server"
#
##s = XMLRPC::CGIServer.new
#s = XMLRPC::Server.new(8080)
#
#class MyHandler
# def sumAndDifference(a, b)
# { "sum" => a + b, "difference" => a - b }
# end
#end
#
#s.add_handler("sample", MyHandler.new)
#s.serve
client.rb
#encoding:utf-8
#! /usr/bin/env ruby
require "xmlrpc/client"
# Make an object to represent the XML-RPC server.
#server = XMLRPC::Client.new( "xmlrpc-c.sourceforge.net", "/api/sample.php")
server = XMLRPC::Client.new2("http://localhost:8080")
# Call the remote server and get our result
result = server.call("sample.sumAndDifference", 5, 3)
sum = result["sum"]
difference = result["difference"]
puts "Sum: #{sum}, Difference: #{difference}"
client.py
#encoding=utf-8
#!/usr/bin/env python
import xmlrpclib
proxy = xmlrpclib.Server('http://localhost:8080')
print proxy.sample.sumAndDifference(5,3)
reference:
http://www.faqs.org/docs/Linux-HOWTO/XML-RPC-HOWTO.html#xmlrpc-howto-ruby-server