Hello all,

I am writing a server/client pair using DRb and I want to be able to inject a foreign object FROM the client INTO the server and have it execute. The biggest problem seems to be letting the server know about the class of the foreign object. I want to be able to specify the class on the fly, basically allowing the server to be a very thin and its software can be specified from the outside. Here some of the code I've been playing with.

Firstly on the server side:

Code:
require 'drb'

class TestServer
	def initialize
		
		@remote = TestRemote.new
		
		DRb.start_service("druby://localhost:7000", @remote)
		
		DRb.thread.join	
	end	
end

class TestRemote
	def remote_eval something
		eval something
	end
	
	def put_something something
		puts something.class.to_s
		something.print_something
	end
end

TestServer.new

Next on the client side:

Code:
require 'drb'

class Something
	def print_something
		puts "something"
	end
end

DRb.start_service

a = Something.new
c = DRbObject.new nil, 'druby://localhost:7000'

c.remote_eval "class Something\n\tdef print_something\n\t\tputs \'something\'\n\tend\nend"
c.put_something a

Finally, when the client is run against the server:
Code:
snowdall$ ruby test_client.rb 
(druby://localhost:7000) test_server.rb:21:in `put_something': undefined method `print_something' for #<DRb::DRbUnknown:0x1cba4c> (NoMethodError)
	from test_client.rb:15

The client first gives the server the specification of the Something class. From there, and instance of Something is handed over to the server but the server doesn't recognize it as the Something class. Instead it casts it as DRbUnknown. It seems that the class definition that is eval'ed in the server ends up as TestServer::Something since it was specified INSIDE the server instance. I want to know if there is anyway to specify a class definition at the top level of the objectspace. I think that would allow me to inject any object I want into the server and have it run.

Any ideas anyone?

Thanks,
Snowdall