# RoR and DRb

**URL:** <https://www.ruby-forum.com/t/ror-and-drb/111609>\
**Category:** Rails\
**Created:** [August 9, 2007, 2:41am UTC](https://www.ruby-forum.com/t/ror-and-drb/111609 "2007-08-09T02:41:55Z")\
**Posts on this page:** 3\
**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 9, 2007, 2:41am UTC](https://www.ruby-forum.com/t/ror-and-drb/111609/1 "2007-08-09T02:41:55Z")

</div>

Hi,

I have a question regarding RoR and DRb. First of all, I tested with  
simple client/server examples and everything worked as expected. I have  
the following lines in my environment.rb:  
DRb.start\_service  
$rem\_obj = DRbObject.new(nil, “druby://#{rname}:9001”)

Since rem\_obj is a global variable, I can call it from any controller  
and the invoked procedure is run on the server.

However, what if you want the client to be registered as an observer.  
How is that gonna work in rails? I imagine that an observer has to be  
running continously, and since rails can only serve page requests how  
can it also listen to the server’s events? Do you have to create a  
listener object which runs in a separate thread or process?

I actually made this work by adding the following line in the  
controller’s initialize() function: DRb.start\_service, but I don’t  
understand why this works. After the page got served, what process is  
still running the observer?

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 9, 2007, 8:22am UTC](https://www.ruby-forum.com/t/ror-and-drb/111609/2 "2007-08-09T08:22:10Z")

</div>

DRb.start\_service (as I understand) spawns a separate thread.

Look at backgroundrb and at Rails observers. I think a combo of them  
can do what you want to do.

Vish

---

<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:43am UTC](https://www.ruby-forum.com/t/ror-and-drb/111609/3 "2007-08-10T01:43:28Z")

</div>

Hi Vish,

Thanks for your answer. I did check the drb source code, and indeed  
start\_service spawns a new thread.  
My mistake was that I was starting my client (and the registration of  
the observers) without restarting my server(s), and that was causing  
some problems. I left start\_service in environment.rb and it works.

Tiberiu

Vishnu G. wrote:

> DRb.start\_service (as I understand) spawns a separate thread.
> 
> Look at backgroundrb and at Rails observers. I think a combo of them  
> can do what you want to do.
> 
> Vish
