XML-RPC WEBrick problem (error during method invocation)

I have a university assignement, and i am stuck. I am supposed to create
a server using xml-rpc with ruby, but I keep getting errors. I am not
very good with ruby, this is actually the first time im working on a
ruby assignement.
The goal is to in the end create 3 client/server programs in 3 different
languages:ruby,c# and java and to have them communicate. sadly i cant
even get it to communicate from ruby to ruby.

here is my server :
require 'webrick'
require 'xmlrpc/server.rb'

class Something<XMLRPC::WEBrickServlet

def initialise()
# create a servlet to handle XML-RPC requests:
servlet = XMLRPC::WEBrickServlet.new
servlet.add_handler("upper_case") { |a_string| a_string.upcase }
servlet.add_handler("help"){|| puts "print some string"}
servlet.add_handler("lower_case") { |a_string| a_string.downcase }

# create a WEBrick instance to host this servlet:
server=WEBrick::HTTPServer.new(:Port => 9090)
trap("INT"){ server.shutdown }
server.mount("/RPC2", servlet)

server.start
end

here is my client:
require 'xmlrpc/client'
server = XMLRPC::Client.new("127.0.0.1", "/RPC2", 9090)

puts server.call("upper_case", "abcd")
puts server.call("lower_case", "HELLO")
server.call("help")

the calls for upper and lower case work fine, but if i want to just puts
a string on the screen, it doesnt seem to work.

C:\Users\Moog\Ruby>xmlclient.rb
ABCD
hello
C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:549:in `do_rpc': HTTP-Error:
500 Inte
rnal Server Error (RuntimeError)
        from C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:420:in `call2'
        from C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:410:in `call'
        from C:/Users/Moog/Ruby/xmlclient.rb:6:in `<main>'

I am completely stuck on this. All help would be greatly appreciated.

···

--
Posted via http://www.ruby-forum.com/.

I have a university assignement, and i am stuck. I am supposed to create
a server using xml-rpc with ruby, but I keep getting errors. I am not
very good with ruby, this is actually the first time im working on a
ruby assignement.
The goal is to in the end create 3 client/server programs in 3 different
languages:ruby,c# and java and to have them communicate. sadly i cant
even get it to communicate from ruby to ruby.

here is my server :
require 'webrick'
require 'xmlrpc/server.rb'

class Something<XMLRPC::WEBrickServlet

def initialise()
# create a servlet to handle XML-RPC requests:
servlet = XMLRPC::WEBrickServlet.new
servlet.add_handler("upper_case") { |a_string| a_string.upcase }
servlet.add_handler("help"){|| puts "print some string"}
servlet.add_handler("lower_case") { |a_string| a_string.downcase }

# create a WEBrick instance to host this servlet:
server=WEBrick::HTTPServer.new(:Port => 9090)
trap("INT"){ server.shutdown }
server.mount("/RPC2", servlet)

server.start
end

The server code is incomplete. I managed to get something to work and
reproduce your problem with a little editing though. Take care to be as
accurate as possible when asking for help with code. :wink:

here is my client:
require 'xmlrpc/client'
server = XMLRPC::Client.new("127.0.0.1", "/RPC2", 9090)

puts server.call("upper_case", "abcd")
puts server.call("lower_case", "HELLO")
server.call("help")

the calls for upper and lower case work fine, but if i want to just puts
a string on the screen, it doesnt seem to work.

C:\Users\Moog\Ruby>xmlclient.rb
ABCD
hello
C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:549:in `do_rpc': HTTP-Error:
500 Inte
rnal Server Error (RuntimeError)
        from C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:420:in `call2'
        from C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:410:in `call'
        from C:/Users/Moog/Ruby/xmlclient.rb:6:in `<main>'

I am completely stuck on this. All help would be greatly appreciated.

Since this is a school assignment, I'll only say that you're very close
to the solution and suggest that you closely watch the output of your
server while you run your client.

Good luck!

-Jeremy

···

On 10/6/2010 5:13 AM, Nikita Kuznetsov wrote:

I am completely stuck on this. All help would be greatly appreciated.

Since this is a school assignment, I'll only say that you're very close
to the solution and suggest that you closely watch the output of your
server while you run your client.

Well, the problem for me is that i already know i am close. I was
advised to try out some things like make a single class containing all
the things i needed. But the problem for me is syntax, i am completely
new to Ruby, so some simple framework guidelines would be great, im not
asking for the exact code, thats up to me to work out anyway, otherwise
this assignement is useless. Im just stuck in one of those moments where
i understand the parts but not the whole and i cant seem to put the
parts together. this may sound a little confusing but i think you
understand what i mean.
If you could just show me how to make a function to run a simple puts
from the server, i would be extremely happy. The output of my server is
usually the same, date+time of connection, that its a POST procedure and
that its http. Doesnt really tell me much.

···

--
Posted via http://www.ruby-forum.com/\.

I attempted a fresh start without using WEBrick.
Does this seem more logical? I am still stuck on the http error 500 and
the output is still on the serverside. I also don't quite understand
what is a NilClass?

my server:
require 'xmlrpc/server'
require 'C:\Users\Moog\Ruby\MyMethods.rb'

class Server

    @manager
     def initialize()
       @manager = MyMethods.new
     end

     def help
      @manager.help
     end
end

server = XMLRPC::Server.new(8080, "127.0.0.1")
server.add_handler("xmlrpc", MyMethods.new)
puts "Server ready!"
server.serve

my client:
require 'xmlrpc/client'
server = XMLRPC::Client.new("127.0.0.1", "/RPC2", 8080)
server.call("xmlrpc.help")

MyMethods.rb:
class MyMethods

  def help
    puts "help"
                puts "help"
    puts ""
    puts "help"
  end
end

my output server side:
[2010-10-07 15:12:38] INFO WEBrick 1.3.1
[2010-10-07 15:12:38] INFO ruby 1.9.2 (2010-08-18) [i386-mingw32]
Server ready!
[2010-10-07 15:12:38] INFO WEBrick::HTTPServer#start: pid=524 port=8080
help
help

help
[2010-10-07 15:12:42] ERROR RuntimeError: Wrong type NilClass. Not
allowed!
        C:/Ruby192/lib/ruby/1.9.1/xmlrpc/create.rb:207:in `conv2value'
        C:/Ruby192/lib/ruby/1.9.1/xmlrpc/create.rb:148:in `block in
methodRespon
se'
        C:/Ruby192/lib/ruby/1.9.1/xmlrpc/create.rb:147:in `collect'
        C:/Ruby192/lib/ruby/1.9.1/xmlrpc/create.rb:147:in
`methodResponse'
        C:/Ruby192/lib/ruby/1.9.1/xmlrpc/server.rb:380:in `handle'
        C:/Ruby192/lib/ruby/1.9.1/xmlrpc/server.rb:312:in `process'
        C:/Ruby192/lib/ruby/1.9.1/xmlrpc/server.rb:758:in `service'
        C:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:111:in `service'
        C:/Ruby192/lib/ruby/1.9.1/webrick/httpserver.rb:70:in `run'
        C:/Ruby192/lib/ruby/1.9.1/webrick/server.rb:183:in `block in
start_threa
d'
PC-de-Moog - - [07/Oct/2010:15:12:42 Paris, Madrid (heure dÆÚtÚ)] "POST
/RPC2 HT
TP/1.1" 500 313
- -> /RPC2
client side.
C:\Users\Moog\Ruby>client.rb
C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:549:in `do_rpc': HTTP-Error:
500 Inte
rnal Server Error (RuntimeError)
        from C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:420:in `call2'
        from C:/Ruby192/lib/ruby/1.9.1/xmlrpc/client.rb:410:in `call'
        from C:/Users/Moog/Ruby/client.rb:5:in `<main>'

I'm guessing here, i'm stuck at the same situation as before, i am
missing something on the server-side, but i really cannot see it. I have
already spent many sleepless nights trying to figure this out.
Could you give me another hint? You don't have to give me the solution
:smiley: i would love to have the facepalming moment myself :smiley:

thanks again for all the assistance already.

···

--
Posted via http://www.ruby-forum.com/.

Nikita Kuznetsov wrote:

Since this is a school assignment, I'll only say that you're very close
to the solution and suggest that you closely watch the output of your
server while you run your client.

Well, the problem for me is that i already know i am close.

Another problem is that you didn't pay attention to Jeremy's advice:
"watch the output of your server while you run your client". Look at
this output, tell us what you think about it, and we'll help you solve
the problem.

···

--
Posted via http://www.ruby-forum.com/\.

I am completely stuck on this. All help would be greatly appreciated.

Since this is a school assignment, I'll only say that you're very close
to the solution and suggest that you closely watch the output of your
server while you run your client.

Well, the problem for me is that i already know i am close. I was
advised to try out some things like make a single class containing all
the things i needed. But the problem for me is syntax, i am completely
new to Ruby, so some simple framework guidelines would be great, im not
asking for the exact code, thats up to me to work out anyway, otherwise
this assignement is useless. Im just stuck in one of those moments where
i understand the parts but not the whole and i cant seem to put the
parts together. this may sound a little confusing but i think you
understand what i mean.

The problem is that you are so near to finding the solution to your
problem that to say much more would give you the answer.

If you could just show me how to make a function to run a simple puts
from the server, i would be extremely happy. The output of my server is
usually the same, date+time of connection, that its a POST procedure and
that its http. Doesnt really tell me much.

Showing such an example would solve your problem entirely, don't you
think? Please don't think I'm making light of your situation. Once you
figure out the problem, you'll definitely have one of those palm-face
moments.

Look closer at that server output, and don't discount anything out of
hand. It may help if you gather the server output generated during a
single run of your client and then identify what client action causes
each line of the server output to be displayed and what each line means.
That's exactly what I did with your sample code (once I corrected the
server code to get something that replicates your issue) to figure out
what's going on.

I know it can be frustrating, but you can just get a certain kind of
blindness to what's going on with your code at times, and the only ways
out are to ask for help (if you can get it, sorry) or really attack your
problem from a different angle. Sometimes it's even good to completely
ignore the code for a day or two and then come back to it with fresh
eyes. I've used all of these techniques numerous times.

Above all, be persistent and have confidence that you will figure this out.

-Jeremy

···

On 10/06/2010 04:47 PM, Nikita Kuznetsov wrote:

i would love to have the facepalming moment myself :smiley:

I just had my facepalm moment... its not "puts", its return!!!
I use puts on the clientside and return on the serverside and it works
great!!!

FACEPALM

···

--
Posted via http://www.ruby-forum.com/.

Look closer at that server output, and don't discount anything out of

hand. It may help if you gather the server output generated during a
single run of your client and then identify what client action causes
each line of the server output to be displayed and what each line means.

Do you mean it printing my answer on the serverside and not the
client-side?
I cannot think of a way how to bypass this.
On a side note, how do i include a file using require. I am thinking of
having a require 'myClass.rb', but i cannot figure out what file path i
have to write for it. In C it was easy, it was just #include
"something.h". I was planning on putting all my methods in one class and
seing how that goes.

···

--
Posted via http://www.ruby-forum.com/\.

Excellent! In your original example you were doing exactly that with
your client side in the first two, successful calls to the server. You
called the server's upper_case and lower_case methods, it returned
strings, and you printed those strings. I promise that it was agonizing
not being able to tell you what was wrong with your server's help
method. :wink:

Keep in mind that in Ruby an explicit use of the return keyword is not
always necessary. If the block of code at hand evaluates to the value
you would like to return, you can leave it at that. Going back to your
original server example, the block for the server's help method could
simply have been { "print some string" }. You can have an explicit
return statement in there, but it's optional and not often done in Ruby
in these cases.

-Jeremy

···

On 10/7/2010 8:31 AM, Nikita Kuznetsov wrote:

i would love to have the facepalming moment myself :smiley:

I just had my facepalm moment... its not "puts", its return!!!
I use puts on the clientside and return on the serverside and it works
great!!!

FACEPALM

On a side note, how do i include a file using require. I am thinking of
having a require 'myClass.rb', but i cannot figure out what file path i
have to write for it. In C it was easy, it was just #include
"something.h". I was planning on putting all my methods in one class and
seing how that goes.

Scratch that, i figured that part out. I was just having type errors

···

--
Posted via http://www.ruby-forum.com/\.