Flowdock
Ruby latest stable (v1_9_3_392) - 0 notes - Superclass: BasicServer

XMLRPC::Server

Synopsis

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

Description

Implements a standalone XML-RPC server. The method (({serve}))) is left if a SIGHUP is sent to the program.

Superclass

((<XMLRPC::WEBrickServlet>))

Class Methods

— XMLRPC::Server.new( port=8080, host=“127.0.0.1”, maxConnections=4, stdlog=$stdout, audit=true, debug=true, *a )

Creates a new (({XMLRPC::Server})) instance, which is a XML-RPC server listening on
port ((|port|)) and accepts requests for the host ((|host|)), which is by default only the localhost.
The server is not started, to start it you have to call ((<serve|XMLRPC::Server#serve>)).

Parameters ((|audit|)) and ((|debug|)) are obsolete!

All additionally given parameters in ((|*a|)) are by-passed to ((<XMLRPC::BasicServer.new>)).

Instance Methods

XMLRPC::Server#serve

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.

XMLRPC::Server#shutdown

Stops and shuts the server down.

XMLRPC::WEBrickServlet

Synopsis

require "webrick"
require "xmlrpc/server"

s = XMLRPC::WEBrickServlet.new
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

httpserver = WEBrick::HTTPServer.new(:Port => 8080)
httpserver.mount("/RPC2", s)
trap("HUP") { httpserver.shutdown }   # use 1 instead of "HUP" on Windows
httpserver.start

Instance Methods

— XMLRPC::WEBrickServlet#set_valid_ip( *ip_addr )

Specifies the valid IP addresses that are allowed to connect to the server.
Each IP is either a (({String})) or a (({Regexp})).

XMLRPC::WEBrickServlet#get_valid_ip

Return the via method ((<set_valid_ip|XMLRPC::Server#set_valid_ip>)) specified
valid IP addresses.

Description

Implements a servlet for use with WEBrick, a pure Ruby (HTTP-) server framework.

Superclass

((<XMLRPC::BasicServer>))

Show files where this class is defined (1 file)
Register or log in to add new notes.