DRb, “who called me” method

In a DRbserver, how can I see who called a method? I want to log the ip
and port from anyone who calls a certain method. something like

def who
uri =
puts uri
end

Is this functionality available in DRb?

Thanks.

Pavlos Vin wrote in post #1006184:

In a DRbserver, how can I see who called a method? I want to log the ip
and port from anyone who calls a certain method. something like

def who
uri =
puts uri
end

Is this functionality available in DRb?

Thanks.

Not that I can find.

But DRb uses the class DRb::DRbTCPSocket to create
the listening server socket, and then the listening socket spins off new
sockets of type
DRb::DRbTCPSocket to handle client connections. Looking at the source
code for DRb::DRbTCPSocket I found the following accept() method:

On the server side, for an instance returned by #open_server,

accept a client connection and return a new instance to handle

the server’s side of this client-server session.

def accept
while true
s = @socket.accept
break if (@acl ? @acl.allow_socket?(s) : true)
s.close
end
self.class.new(nil, s, @config)
end

You can hack that method to log peer addresses:

#DRb server program:

require ‘drb/drb’

class DRb::DRbTCPSocket
def accept
while true
s = @socket.accept
break if (@acl ? @acl.allow_socket?(s) : true)
s.close
end

  client_socket = self.class.new(nil, s, @config)
  p client_socket.peeraddr
  client_socket

end

end

class TimeServer

def get_current_time
return Time.now
end

end

The object that handles requests on the server

FRONT_OBJECT=TimeServer.new

$SAFE = 1 # disable eval() and friends

URI = “druby://localhost:12000”
DRb.start_service(URI, FRONT_OBJECT)

Wait for the drb server thread to finish before exiting.

DRb.thread.join

–output:–
[“AF_INET6”, 63420, “localhost”, “::1”]
[“AF_INET6”, 63675, “localhost”, “::1”]
[“AF_INET6”, 63676, “localhost”, “::1”]

Ah, this would have been a better place to reply, but see reply at
http://www.ruby-forum.com/topic/1962357#1006460

yes… that’s probably the way i’m gonna go.

i looked around in the source code and found this accept method, but i
hoped for a “cleaner” solution.

oh well… that’ll do the job.

thanks!