From: "Anders Engström" Date: 2005-02-24T07:03:07+09:00 Subject: Re: Ways of obtaining a remote peer's IP address from distributed ruby? On Thu, Feb 24, 2005 at 06:44:12AM +0900, Dido Sevilla wrote: > 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 -- . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . Anders Engstr�m aengstrom@gnejs.net . http://www.gnejs.net PGP-Key: ED010E7F . [Your mind is like an umbrella. It doesn't work unless you open it.]