Simple Net::HTTP operation is eluding me

I am coming to Ruby from Java and I must say it is fantastic!

Something that should be basic is eluding me, however. Despite
searching through the PP guide, online references, and usenet posts, I
cannot figure out how to create a Net::HTTP object bound to a specific
local IP address of my choosing. It always seems to want to use
’localhost’. I am using Ruby 1.6. I just discovered the RAA, are
there perhaps any libraries on there that could help?

Any pointers in the right direction would be much appreciated.

Kevin Pauli wrote:

I am coming to Ruby from Java and I must say it is fantastic!

Something that should be basic is eluding me, however. Despite
searching through the PP guide, online references, and usenet posts, I
cannot figure out how to create a Net::HTTP object bound to a specific
local IP address of my choosing. It always seems to want to use
‘localhost’. I am using Ruby 1.6. I just discovered the RAA, are
there perhaps any libraries on there that could help?

Any pointers in the right direction would be much appreciated.

You do pass the local IP in to the new method?
http://www.rubycentral.com/book/lib_network.html#Net::HTTP.new

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)

Kent Dahl kentda@stud.ntnu.no wrote in message news:3DBA3430.92240B21@stud.ntnu.no

Kevin Pauli wrote:

I am coming to Ruby from Java and I must say it is fantastic!

Something that should be basic is eluding me, however. Despite
searching through the PP guide, online references, and usenet posts, I
cannot figure out how to create a Net::HTTP object bound to a specific
local IP address of my choosing. It always seems to want to use
‘localhost’. I am using Ruby 1.6. I just discovered the RAA, are
there perhaps any libraries on there that could help?

Any pointers in the right direction would be much appreciated.

You do pass the local IP in to the new method?
http://www.rubycentral.com/book/lib_network.html#Net::HTTP.new

Thanks for the response. That address argument seems to be the target
address. I need to specify the IP address to use on the machine where
the Ruby interpreter is running. (My machine is multi-homed, with
several IP addresses bound to it). For example, I would expect
something like this java.net.Socket constructor provides:

public Socket(InetAddress address, int port, InetAddress localAddr,
int localPort)

Notice that you can specify the local address and port as well as the
target address and port.

Am I missing something in the Ruby version, or is the capability
simply not available?

Kevin Pauli wrote:

Thanks for the response. That address argument seems to be the target
address.

Sorry, the ‘localhost’ bit threw me off.

I need to specify the IP address to use on the machine where
the Ruby interpreter is running. (My machine is multi-homed, with
several IP addresses bound to it). For example, I would expect
something like this java.net.Socket constructor provides:

public Socket(InetAddress address, int port, InetAddress localAddr,
int localPort)

Notice that you can specify the local address and port as well as the
target address and port.

Am I missing something in the Ruby version, or is the capability
simply not available?

I went looking a bit, but couldn’t find anything that does it directly.
I noticed that UDPSocket has a method bind for setting the local
address, but I can’t find anything similar in TCPSocket. The constructor
for TCPSocket in 1.7 seems to take an argument for the local address,
but how to get that to influence the Net::HTTP?

However, from what I can gather, it might be possible to twiddle this
with setsockopt. If this option can be changed after the initial
connection has been made, you could instance_eval on the Net::HTTP to
get the socket, but what options, level etc to call setsockopt with, I
have no idea.

HTH a little more than my last post. :slight_smile:

···


([ Kent Dahl ]/)_ ~ [ http://www.stud.ntnu.no/~kentda/ ]/~
))_student
/(( _d L b_/ NTNU - graduate engineering - 5. year )
( __õ|õ// ) )Industrial economics and technological management(
_
/ö____/ (_engineering.discipline=Computer::Technology)