# Ruby on rails and drb

**URL:** <https://www.ruby-forum.com/t/ruby-on-rails-and-drb/111533>\
**Category:** Rails\
**Created:** [August 8, 2007, 10:46am UTC](https://www.ruby-forum.com/t/ruby-on-rails-and-drb/111533 "2007-08-08T10:46:10Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![mr\_tibs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@mr\_tibs](https://www.ruby-forum.com/u/mr_tibs)\
**Post date:** [August 8, 2007, 10:46am UTC](https://www.ruby-forum.com/t/ruby-on-rails-and-drb/111533/1 "2007-08-08T10:46:10Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![mr\_tibs](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/439d5e/32.png) [@mr\_tibs](https://www.ruby-forum.com/u/mr_tibs)\
**Post date:** [August 10, 2007, 1:52am UTC](https://www.ruby-forum.com/t/ruby-on-rails-and-drb/111533/2 "2007-08-10T01:52:19Z")

</div>

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
