Class: XMLRPC::Server
- Inherits:
-
WEBrickServlet
- Object
- BasicServer
- WEBrickServlet
- XMLRPC::Server
- Defined in:
- lib/xmlrpc/server.rb
Overview
Implements a standalone XML-RPC server. The method XMLRPC::Server#serve is left if a SIGHUP is sent to the program.
require "xmlrpc/server"
s = XMLRPC::Server.new(8080)
s.add_handler("michael.add") do |a,b|
a + b
end
s.add_handler("michael.div") do |a,b|
if b == 0
raise XMLRPC::FaultException.new(1, "division by zero")
else
a / b
end
end
s.set_default_handler do |name, *args|
raise XMLRPC::FaultException.new(-99, "Method #{name} missing" +
" or wrong number of parameters!")
end
s.serve
Constant Summary
Constants inherited from BasicServer
BasicServer::ERR_MC_EXPECTED_STRUCT, BasicServer::ERR_MC_MISSING_METHNAME, BasicServer::ERR_MC_MISSING_PARAMS, BasicServer::ERR_MC_RECURSIVE_CALL, BasicServer::ERR_MC_WRONG_PARAM, BasicServer::ERR_MC_WRONG_PARAM_PARAMS, BasicServer::ERR_METHOD_MISSING, BasicServer::ERR_UNCAUGHT_EXCEPTION
Instance Method Summary collapse
-
#initialize(port = 8080, host = "127.0.0.1", maxConnections = 4, stdlog = $stdout, audit = true, debug = true, *a) ⇒ Server
constructor
Creates a new XMLRPC::Server instance, which is a XML-RPC server listening on the given
portand accepts requests for the givenhost, which islocalhostby default. -
#serve ⇒ Object
Call this after you have added all you handlers to the server.
-
#shutdown ⇒ Object
Stops and shuts the server down.
Methods inherited from WEBrickServlet
#get_instance, #get_valid_ip, #require_path_info?, #service, #set_valid_ip
Methods inherited from BasicServer
#add_handler, #add_introspection, #add_multicall, #get_default_handler, #get_service_hook, #process, #set_default_handler, #set_service_hook
Methods included from ParseContentType
Methods included from ParserWriterChooseMixin
Constructor Details
#initialize(port = 8080, host = "127.0.0.1", maxConnections = 4, stdlog = $stdout, audit = true, debug = true, *a) ⇒ Server
Creates a new XMLRPC::Server instance, which is a XML-RPC server listening on the given port and accepts requests for the given host, which is localhost by default.
The server is not started, to start it you have to call XMLRPC::Server#serve.
The optional audit and debug parameters are obsolete!
All additionally provided parameters in *a are by-passed to XMLRPC::BasicServer.new.
574 575 576 577 578 579 580 |
# File 'lib/xmlrpc/server.rb', line 574 def initialize(port=8080, host="127.0.0.1", maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a) super(*a) require 'webrick' @server = WEBrick::HTTPServer.new(:Port => port, :BindAddress => host, :MaxClients => maxConnections, :Logger => WEBrick::Log.new(stdlog)) @server.mount("/", self) end |
Instance Method Details
#serve ⇒ Object
Call this after you have added all you handlers to the server. This method starts the server to listen for XML-RPC requests and answer them.
584 585 586 587 588 589 |
# File 'lib/xmlrpc/server.rb', line 584 def serve signals = %w[INT TERM HUP] & Signal.list.keys signals.each { |signal| trap(signal) { @server.shutdown } } @server.start end |
#shutdown ⇒ Object
Stops and shuts the server down.
592 593 594 |
# File 'lib/xmlrpc/server.rb', line 592 def shutdown @server.shutdown end |