On 10/4/06, Alex Fenton <alex / deleteme.pressure.to> wrote:
> Hi
>
> I'd like to use druby, but with the client using just an IP address to contact the server, and vice versa. The initial connection works fine, but then it seems the server can't find the client to send a reply when a method is invoked.
>
> I realise this question has been asked before, and answered by 'fix your DNS' or 'tweak etc/hosts'.
>
> However, this is for an end-user app, so most users (of clients and servers) won't be permitted to access etc/hosts, even if I wanted to explain what they should do to it.
>
> So
> - has anyone hacked drb to work without hostnames?
> - failing that, is there a deep technical reason that using IP addresses only will never work and I shouldn't bother even trying? It seems lots of other net applications work fine without caring that DNS is fixed, but I've not got masses of experience with socket programming in Ruby.

I'm not sure what isn't working for you with out some code. I do have
an idea though this seems to work for me:

# Server's irb session:
>> require 'drb'
=> true
>> DRb.start_service('druby://192.168.0.104:1234', "abc")
=> #<DRb::DRbServer ....>

# Client's session:
>> require 'drb'
=> true
>> DRb.start_service('druby://192.168.0.101:1234')
=> DRb::DRbServer ....>
>> remote = DRbObject.new(nil, 'druby://192.168.0.104:1234')
=> #<DRb::DRbObject ....>
>> remote.to_s # Force display
=> "abc"
>> remote.size
=> 3
>> remote.replace("ruby")
=> #<DRb::DRbObject ....>
>> remote.to_s
=> "ruby"
>> remote.size
=> 4

Note that it is a good idea to specify an explicit interface on the
client side so you make sure it binds to something the server can
reach. Some systems will bind to something like 127.0.0.1 when
resolving the host's name (i.e. Ubuntu does this). The two way channel
is vital to have DRb work reliably in most cases (unmarshalled objects
can be referenced in both directions).

Brian.