Logging DRb source IP address


#1

I use Drb to talk from a number of clients to a central server. I have
logging on the server that records the method called and the arguments
that it was called with. I’d like to include the IP address that the Drb
request came from, but I can’t find any way to get that information. Is
the information available? If so how do I get it? If not, does anybody
know why not?

thanks,

Anthony W…


#2

Anthony W. wrote in post #1025900:

I use Drb to talk from a number of clients to a central server. I have
logging on the server that records the method called and the arguments
that it was called with. I’d like to include the IP address that the Drb
request came from, but I can’t find any way to get that information. Is
the information available? If so how do I get it? If not, does anybody
know why not?

The nice thing about DRb is it’s all pure ruby. Digging about a bit:

def main_loop
  Thread.start(@protocol.accept) do |client|
    @grp.add Thread.current
    Thread.current['DRb'] = { 'client' => client ,
                              'server' => self }

So in your method handler, try looking at
Thread.current[‘DRb’][‘client’]. I think that will be a DRbTCPSocket
object with a peeraddr method.

Simple demo (client and server in the same code):

require “drb”
class Foo
def doit
return “You are #{Thread.current[‘DRb’][‘client’].peeraddr.inspect}”
end
end

DRb.start_service(“druby://0.0.0.0:9999”, Foo.new)

o = DRbObject.new_with_uri(“druby://127.0.0.1:9999”)
puts o.doit