Druby - How to close connection from client?

I need to disconnect explicitly from a druby client.

My code is like:

DRb.start_service
@drb = DRbObject.new(nil, ‘druby://localhost:7777’)
@drb.dosomething(param1, param2, param3)
…(here I’d like to disconnect!!)…

Background:
I am using druby to communicate between a Rails application running on
lighttpd/FreeBSD6 and a server-script running on the same box with
different
user rights.

I noticed that the longer I run the webserver the more sockets stay
open,
“sockstat | grep ruby” gives me hundreds of:

www ruby18 26179 10 tcp4 *:51359 :
www ruby18 26179 11 tcp4 *:57690 :
www ruby18 26179 12 tcp4 *:53473 :

I assume that every time I run the druby client on the website a
connection
remains open. They get all cleared if I restart lighttpd.

Thanks.
martin

On 7/25/06, Martin B. [email protected] wrote:

I need to disconnect explicitly from a druby client.

My code is like:

DRb.start_service
@drb = DRbObject.new(nil, ‘druby://localhost:7777’)
@drb.dosomething(param1, param2, param3)
…(here I’d like to disconnect!!)…

DRb.stop_service

You can make another call to DRb.start_service if you want to restart
your DRb connection. You’ll have to create another DRbObject, though,
since stop_service terminates all connections.

Blessings,
TwP

Martin B. wrote:

Background:
I am using druby to communicate between a Rails application running on
lighttpd/FreeBSD6 and a server-script running on the same box with different
user rights.

Martin- I’m doing something similar but using Rinda as a middle man.
What I did was create a singleton class to handle the conenction, one
connection stays open and gets reused.

Here’s what the client looks like.

#!/usr/bin/env ruby -w

require ‘rinda/ring’
require ‘uuidtools’
require ‘rinda’
require ‘search_result’

class SearchClient
private_class_method :new
@@tuple_space = nil

def self.create
if @@tuple_space.nil?
DRb.start_service
@@tuple_space = Rinda::TupleSpaceProxy.new(DRbObject.new(nil,
RINDA_MASTER))
end
@@tuple_space
end

def self.user_search(opts)
retries = 0
begin
opts[:uuid] = UUID.random_create.to_s
puts “outgoing => uuid: #{opts[:uuid]}\nopts: #{opts}”
SearchClient.create.write([:UserSearch, DRb.uri, opts],
RINDA_TIMEOUT)
tuple = SearchClient.create.take([:UserSearchResults,
opts[:uuid], nil], RINDA_TIMEOUT)
SearchResult.new tuple[2]
rescue DRb::DRbConnError
# handle connection closed
rescue
@@tuple_space = nil
raise ‘Connection Error’
end
end
end

That’s great! I will for sure look into this plugin…

For now I just do DRb.stop_service as suggested by Tim and it seems to
work
fine.

Thanks everybody for the nice help.

Martin

On Jul 25, 2006, at 1:25 AM, Martin B. wrote:

Background:

www ruby18 26179 11 tcp4 *:57690 :
www ruby18 26179 12 tcp4 *:53473 :

I assume that every time I run the druby client on the website a
connection
remains open. They get all cleared if I restart lighttpd.

Thanks.
martin

He Martin-

You may want to have a look at a rails plugin I wrote called

BackgrounDRb [1]. Its built for this exact purpose. You can have
worker classes that run in the drb server that you can start and stop
from rails. It also has hooks and examples of how to create ajax
progress bars while your workers do their task.

Cheers-
-Ezra

[1] http://backgroundrb.rubyforge.org/