druby two-way communication question

B

Brian Schroeder

Hello everybody,

I'm stuck with a simple task I want to complete using druby.

I have a server and some client processes. It is easy to make the client
execute code on the server side. But now I want to call back to the client
and execute a function there. But as soon as I pass a client object or
lambda function to the server, it blows up.

Here are my thoughts so far as a minimal example (I really tried to make
it short, so no $SAFE and friends):

== server.rb ==
require 'drb/drb'

class RemoteControl
include DRb::DRbUndumped

def initialize(client)
@client = client
end

def callback
@client.callback
end
end

# The drb server
class Server
def initialize(uri)
@clients = []
DRb.start_service(uri, self) # Start drb service
end

def connect(client)
remote_control = RemoteControl.new(self, clientcallback) @clients <<
remote_control
remote_control
end
end


TheServer = Server.new('druby://localhost:12345')

DRb.thread.join # Wait for the drb server thread to finish before exiting.
== eof ==

== client.rb ==
require 'drb/drb'

class RemoteControl
include DRb::DRbUndumped

def initialize(uri = 'druby://localhost:12345')
@server = DRbObject.new_with_uri(uri) @remote = @server.connect(self)
end

def act
@remote.callback
end

def callback
puts "Called back"
end
end

r = RemoteControl.new
r.act
r = nil
== eof ==

It blows up with:
/usr/lib/ruby/1.8/drb/drb.rb:1513:in `current_server':
DRb::DRbServerNotFound (DRb::DRbConnError)
from /usr/lib/ruby/1.8/drb/drb.rb:1575:in `to_id' from
/usr/lib/ruby/1.8/drb/drb.rb:981:in `initialize' from
/usr/lib/ruby/1.8/drb/drb.rb:542:in `new' from
/usr/lib/ruby/1.8/drb/drb.rb:542:in `dump' from
/usr/lib/ruby/1.8/drb/drb.rb:581:in `send_request' from
/usr/lib/ruby/1.8/drb/drb.rb:580:in `each' from
/usr/lib/ruby/1.8/drb/drb.rb:580:in `send_request' from
/usr/lib/ruby/1.8/drb/drb.rb:849:in `send_request' from
/usr/lib/ruby/1.8/drb/drb.rb:1088:in `send_message' from
/usr/lib/ruby/1.8/drb/drb.rb:1014:in `method_missing' from
/usr/lib/ruby/1.8/drb/drb.rb:1013:in `open' from
/usr/lib/ruby/1.8/drb/drb.rb:1013:in `method_missing' from
./drb.client.test.rb:11:in `initialize' from
./drb.client.test.rb:23:in `new' from ./drb.client.test.rb:23

which is not really helpful to me.

$ ruby -v
ruby 1.8.1 (2004-02-03) [i386-linux]

Thanks a lot for your help.

Brian
 
N

Nathaniel Talbott

I'm stuck with a simple task I want to complete using druby.

I have a server and some client processes. It is easy to make the
client
execute code on the server side. But now I want to call back to the
client
and execute a function there. But as soon as I pass a client object or
lambda function to the server, it blows up.

Here are my thoughts so far as a minimal example (I really tried to
make
it short, so no $SAFE and friends):

There are a few slight glitches (probably left from when you cut it
down), but the main problem is that you forgot to call
DRb.start_service on the client before trying to connect to the server.
Once I added that, it worked for me.

HTH,


Nathaniel
Terralien, Inc.

<:((><
 
B

Brian Schroeder

On Sat, 24 Jul 2004 00:56:03 +0900, Nathaniel Talbott wrote:

but the main problem is that you forgot to call
DRb.start_service on the client before trying to connect to the server.
Once I added that, it worked for me.

HTH,

That helped indeed. Thanks for taking the time to try out my example and
giving advice.

Regards,

Brian
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top