I have next code
require 'rack/rpc'
class Server < Rack::RPC::Server
def hello_world
"Hello, world!"
end
rpc 'hello_world' => :hello_world
end
server = Server.new
use Rack::RPC::Endpoint, server
run server
script name is server.ru
I’m starting server with command
thin start -R server.ru
>> Thin web server (v1.3.1 codename Triple Espresso)
>> Maximum connections set to 1024
>> Listening on 0.0.0.0:3000, CTRL+C to stop
Also client example
require "xmlrpc/client"
# Make an object to represent the XML-RPC server.
server = XMLRPC::Client.new( "0.0.0.0", "/rpc", 3000)
# Call the remote server and get our result
result = server.call("hello_word")
puts result
next command gives me exception
ruby client.rb
client.rb:414:in `call': Method hello_word missing or wrong number of parameters! (XMLRPC::FaultException)
from client.rb:7:in `<main>'
Why hello_word can’t be found? Thank you.
This is just a typo. You are calling
hello_wordinstead ofhello_worldtry:this should do the trick. I do not think that you can start the server with the
run serverin your Rackup file. Of course you need arunstatement in your config.ru but running an instance of your server class is pointless, because it doesn’t even have acallmethod. In practice you would mount another application there, for example:I also needed to include the
buildergem in order to get this to work.