浙江省高等学校教师教育理论培训

微信搜索“毛凌志岗前心得”小程序

  博客园  :: 首页  :: 新随笔  :: 联系 :: 订阅 订阅  :: 管理

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

 

posted on 2012-01-24 20:39  lexus  阅读(285)  评论(0编辑  收藏  举报