Logging DRb source IP address

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?


Anthony Wright.


Re: Logging DRb source IP address

By Brian Candler at 10/11/2011 - 15:22

Anthony Wright wrote in post #1025900:
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}"


o = DRbObject.new_with_uri("druby://")
puts o.doit