So, we are supposed to create an xml-rpc based event manager using 2-3
programming languages. C#, Java, Ruby.
I opted for ruby(i did this course last year but the dropped out).
So, this time i am really trying.
The code is not the actual problem for me.
It is the testing.
Right now i am attempting this: my usual machine(windows 7), and a
virtual machine running windows xp.
in both there is the same program:
require "xmlrpc/server"
require "xmlrpc/client"
eventCounter=0
t1=Thread.new{
s = XMLRPC::Server.new(8080)
s.add_handler("add") do|id,date,time,duration,header,comment|
eventCounter=eventCounter+1
File.open("#{id}"+".event", 'w') {|f| f.write("#{date}| #{time}|
#{duration}| #{header}| #{comment}") }
end
s.add_handler("delete")do |id|
File.delete("#{id}"+".event")
end
s.set_default_handler do |name, *args|
raise XMLRPC::FaultException.new(-99, "Method #{name} missing" +
" or wrong number of parameters!")
end
s.serve
}
t2=Thread.new{
server = XMLRPC::Client.new("127.0.0.1", "/RPC2", 8080)
begin
puts "Press 1 to add an event\n"
puts "Press 2 to remove an event of given ID\n"
whatToDo=gets.to_i
while whatToDo!="-1"
puts "Press 1 to add an event\n"
puts "Press 2 to remove an event of given ID\n"
whatToDo=gets.to_i
case whatToDo
when 1
server.call("add",eventCounter,"03/10/2011","sadkfdsa","not
long","some header","some comment")
when 2
puts "Input ID to delete\n"
id=gets.to_i
server.call("delete",id)
else
puts "Please input 1 or 2"
end
#server.call("delete","2") Delete example
end
end
}
t2.join
One one computer i am running port 8080, on the other 8090 for the
xmlrpc::server.new
I was also wondering, which ip do i have to write? i tried 127.0.0.1 but
that ofcourse executes locally.
I tried 192.168.0.7 and .8 depending on the machines(their
corresponding ip for the router).
I also tried my web ip, but ofc that is the same for both machines cos
i'm behind 1 router.
Can some1 please help me in this part? If i get past this, i can test my
code everytime i plan something. This ofcourse means i can do my
assignment.
Ofcourse i opened the ports 8080 and 8090 in my router.
I have also attempted running the example code for xmlrpc server and
client.
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
require "xmlrpc/client"
server = XMLRPC::Client.new("www.ruby-lang.org", "/RPC2", 8080)
begin
param = server.call("michael.add", 4, 5)
puts "4 + 5 = #{param}"
rescue XMLRPC::FaultException => e
puts "Error:"
puts e.faultCode
puts e.faultString
end
I really have no idea what i am doing wrong. And i do understand it isnt
really a ruby question, but i really have no idea where i could ask a
question like this
If somebody can solve this, then cyber beer is yours forever
Regards, Nikita
···
--
Posted via http://www.ruby-forum.com/.