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.
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 likedef who
uri =
puts uri
endIs 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:
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
FRONT_OBJECT=TimeServer.new
$SAFE = 1 # disable eval() and friends
URI = “druby://localhost:12000”
DRb.start_service(URI, FRONT_OBJECT)
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!
This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.
Sponsor our Newsletter | Privacy Policy | Terms of Service | Remote Ruby Jobs