Ways of obtaining a remote peer's IP address from distributed ruby?

D

Dido Sevilla

Is there a way to let a method called via druby over TCP/IP learn the
IP address of the remote peer invoking it? If not, is there a way to
allow a local node to obtain its own IP address? I'm writing a program
that involves having clients connect to a server and register
addresses where they can be contacted via druby whenever asynchronous
events later occur. They will then get called by the server when the
asynchronous event occurs. DRb.uri gives useless results for this
application because DRb seems to always use the machine's actual
hostname in the URI, which usually doesn't resolve because many of
the clients have dynamic IP's and don't have valid hostnames as such,
especially the Windows boxes which run the client.
 
A

Anders Engström

Is there a way to let a method called via druby over TCP/IP learn the
IP address of the remote peer invoking it? If not, is there a way to
allow a local node to obtain its own IP address? I'm writing a program
that involves having clients connect to a server and register
addresses where they can be contacted via druby whenever asynchronous
events later occur. They will then get called by the server when the
asynchronous event occurs. DRb.uri gives useless results for this
application because DRb seems to always use the machine's actual
hostname in the URI, which usually doesn't resolve because many of
the clients have dynamic IP's and don't have valid hostnames as such,
especially the Windows boxes which run the client.

I had the same question a couple of months ago - and thanks to
#ruby-lang@FreeNode and some code-browsing I found out that the
following should work (in most cases):

(in a distributed object instance)
def client_address()
if client = Thread.current['DRb']['client']
return client.peeraddr if client.respond_to?:)peeraddr)
end
end

DRb binds some useful stuff to the executing thread - but this is very
un-documented :/ I'm not sure how reliable this is from one version to
the next.

//Anders
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top