ruby on rails and drb

Hi,

I'm trying to get a simple ROR and DRb program to work and I have a question about how ROR works.

My application has a server and a client which is part of a ROR application. The server is simple enough and it has one function: def do_something(listener)   add_observer(listener)   puts 'message on the server' end

The ROR application has one controller which calls the do_something function when a button is pressed on the page. I placed the DRb.start_service() and DRbObject.new() functions in evironment.rb and I placed the reference to the remote object into a global variable. The controller would then simply call: $rem_obj.do_something(listener). listener is an instance of a Listener class which looks like this: class Listener   include DRbUndumped   def update(rhost_name, exit_value)     puts 'message received from the host'   end end

The problem that I'm having is that an observer (the listener object in this case) should be running at all times after the registration (add_observer in do_something) with the remote object. I read that ROR is not multithreaded (and thus I learned about backgroundrb), and it cannot listen to both web requests and updates from the server. How can it even keep listener running?. Indeed, I get "DRb::DRbConnError", druby://localhost:42531 - #<Errno::ECONNREFUSED: Connection refused - connect(2)>, in add_observer on the client.

The strange part is that I put DRb.start_service() in the initialize() function of the controller and it magically works. How is this possible? Upon a page request, after initialize() is called and the request gets serviced, how does the server still have a reference to listener? I cannot believe that listener runs in a different thread, because I didn't create one and the framework didn't provide one.

Thanks, Tiberiu

I found the problem: I was not restarting my server(s) before restarting the client rails application and the registration of the observers was not done correctly. Also, for those who like to know, start_service does spawn a new thread, thus that's how it works.

Tiberiu