XMLRPC beginner confusion,

Hi guys, I’m trying to make a simple XML-RPC chat program in order to
get a bit more used to the interface. My Ruby knowledge is not
great(sadly, its a funky language). So far i did a small program which
does this:

Server:
require “xmlrpc/server”

s = XMLRPC::Server.new(8080)

s.add_handler(“hello”) do |inputString|
#inputString is passed from the client point
system(‘cls’)
puts “#{inputString}”
#output the String
something=gets
#get a response to send to the client

end

s.set_default_handler do |name, *args|
raise XMLRPC::FaultException.new(-99, “Method #{name} missing” +
" or wrong number of parameters!")
end

s.serve

Question 1. Do i need the s.set_default_handler?(as im not calling that
handler. Is this a part that should be part of the code (like the
default part in a switch statement in C)?

Here is my Client:

require “xmlrpc/client”

server = XMLRPC::Client.new(“127.0.0.1”, “/RPC2”, 8080)
begin
system(‘cls’) #just cleaning up the console

#the next few lines are just to do an infinite loop over the handler
call.
a=1
b=2
while a!=b do
puts server.call(“hello”,"#{textInput=gets}")
#calls the handler “hello” on the server and gives it my input and then
outputs the value in the server once a user types something in

end

rescue XMLRPC::FaultException => e
puts “Error:”
puts e.faultCode
puts e.faultString
end

Question 2. Do i really need the exception catch? I’m not really
talented with exception at the moment.

Point of the code:
Step 1: I boot up the server.
Step 2: I launch the client.
Step 3: on client side, write some text, hit enter,
Step 4: the text appears on server side, then type something on server
side, hit enter and it goes to client side.

This is all great, BUT ONE BIG ANNOYING THING:

This is really the most important part for me.

validation.sls.microsoft.com - - [03/Oct/2011:08:38:44 Romance Daylight
Time] “P
OST /RPC2 HTTP/1.1” 200 149

  • -> /RPC2

This is the output everytime the server sends a response to the client.
How can i get rid of this? I understand it must be in one of the files
that i am including. But i cannot seem to find the right part. Anybody
got an idea?
Thanks a million in advance,
Kuznetsov Nikita

Nikita Kuznetsov wrote in post #1024719:

This is all great, BUT ONE BIG ANNOYING THING:

This is really the most important part for me.

validation.sls.microsoft.com - - [03/Oct/2011:08:38:44 Romance Daylight
Time] “P
OST /RPC2 HTTP/1.1” 200 149

  • -> /RPC2

This is the output everytime the server sends a response to the client.
How can i get rid of this? I understand it must be in one of the files
that i am including.

It looks like a log entry to me - something pretty useful for a server
to generate, I’d say.

If you want to find how it’s generated, just look at the source code. On
my system the code for xmlrpc/server is at

/usr/lib/ruby/1.8/xmlrpc/server.rb

And you’ll find the documentation embedded:

== 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>)).

You’ll see the stdlog parameter is passed to WEBrick::Log.new. It should
be easy from there to work out what to pass to suppress the log, or to
write it to a file instead.

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs