Got it Joel.

I'll give it a try tomorrow morning.

Thanks again! :-)

On 8/9/05, Joel VanderWerf <vjoel / path.berkeley.edu> wrote:
> Joel VanderWerf wrote:
> > Ryan Leavengood wrote:
> >
> >>Christopher Aldridge said:
> >>
> >>
> >>>Any suggestions or am I doing it the only way it can be done?
> >>
> >>
> >>If I understand your problem correctly, the issue is that you now have to
> >>constantly poll the server to see if there are more lines, when really
> >>what you want is to have the server tell the clients of the new lines.
> >>
> >>So your options are either to code the clients so they also have a DRb
> >>server, which the server connects to when outputting lines from the log
> >>file, or possible to use Rinda and a Tuplespace.
> >
> >
> > IIRC, the client can also call a method with a block. The block is
> > undumped, so it remains on the client side, with a proxy on the server
> > side. When the server's implementation of the method yields to the
> > block, it calls the code on the client side. DRb is sooo elegant!
> >
> > An example of that idea is embedded in a little distributed chat server
> > example that comes with my foxtails project, using distributed observers
> > wired up to fox gui widgets. But it's probably easier to code this up
> > from scratch, once you know that DRb supports distributed block yields.
> >
> 
> Here is an example of using callbacks by yielding from the server:
> 
> ==== svr.rb ====
> require 'drb'
> 
> $callback = nil
> 
> class C
>   def foo
>     3.times do |i|
>       yield i
>     end
>   end
> 
>   def bar(&pr)
>     $callback = pr
>   end
> end
> 
> obj = C.new
> 
> DRb.start_service('druby://:22337', obj)
> 
> begin
>   loop do
>     $callback.call if $callback
>     sleep 1
>   end
> rescue DRb::DRbConnError
>   puts "client is gone"
> end
> =========
> 
> ==== clnt.rb ====
> require 'drb'
> 
> DRb.start_service()
> obj = DRbObject.new_with_uri('druby://:22337')
> 
> obj.foo do |i|
>   p i
> end
> 
> obj.bar do
>   puts "Got callback!"
> end
> 
> puts "press return to quit"
> gets
> ========
> 
> output:
> 
> 0
> 1
> 2
> press return to quit
> Got callback!
> Got callback!
> Got callback!
> Got callback!
> 
> --
>       vjoel : Joel VanderWerf : path berkeley edu : 510 665 3407
> 
>