How can one use TCPServer with more than one network card; e.g. how
can one choose which network card to bind to?
···
–
ed
How can one use TCPServer with more than one network card; e.g. how
can one choose which network card to bind to?
–
ed
It's the first argument to the constructor...
server = TCPServer.new('192.168.0.1', port)
See: http://www.rubycentral.com/book/lib_network.html
On Sun, Jan 05, 2003 at 05:56:30AM +0900, Edward Wilson wrote:
How can one use TCPServer with more than one network card; e.g. how
can one choose which network card to bind to?
I tried this before but it doesn’t work.
TCPServer binds to the first network card e.g. eth0; Java has this
same problem. Changing the “ip string” doesn’t change the network
card…at least from my experience.
The problem I’m having is that I can only bind to the first network
card in my hardware array. I have to reassign IPs to my hardware;
what I want to be able to do is pass different parrameters to
TCPServer or perhaps it’s super class and override TCPServer to be
able to bind to `any of several network cards’ I may have configured
on a given machine. Each network card has it’s own IP, but like I
said, TCPServer appears to have a limitation of only being able to see
the first network card, so it only works if the IP you pass it is the
same as your first network card.
–
ed
Brian Candler B.Candler@pobox.com wrote in message news:20030104232156.GA9436@uk.tiscali.com…
On Sun, Jan 05, 2003 at 05:56:30AM +0900, Edward Wilson wrote:
How can one use TCPServer with more than one network card; e.g. how
can one choose which network card to bind to?It’s the first argument to the constructor…
server = TCPServer.new(‘192.168.0.1’, port)
I tried this before but it doesn't work.
TCPServer binds to the first network card e.g. eth0; Java has this
same problem. Changing the "ip string" doesn't change the network
card...at least from my experience.
TCPServer has no concept of a "network card" nor of named interfaces like
"eth0".
TCPServer('0.0.0.0',1234) will bind to 0.0.0.0 which means "accept
connections on any interface"
TCPServer('192.168.0.1',1234) will bind only to interface 192.168.0.1. If
your machine has other interfaces, including the loopback (127.0.0.1) then
attempts to connect to port 1234 on those addresses will be refused by the
O/S.
The bind address is just passed as a parameter to the O/S socket layer. I
assume that because you say "eth0" you are running on a Unix not Windoze
system, in which case it's the Unix socket code you are talking to. Ruby is
not doing anything clever with it.
The problem I'm having is that I can only bind to the first network
card in my hardware array. I have to reassign IPs to my hardware;
what I want to be able to do is pass different parrameters to
TCPServer or perhaps it's super class and override TCPServer to be
able to bind to `any of several network cards' I may have configured
on a given machine. Each network card has it's own IP, but like I
said, TCPServer appears to have a limitation of only being able to see
the first network card, so it only works if the IP you pass it is the
*same* as your first network card.
Then I think you have misunderstood what it means to "bind" to an interface.
If you pass the IP address of your first network card, then indeed it will
only answer queries to that card's IP address.
A good book if you are interested in the gory details is "Advanced
Programming in the Unix environment" (Stevens, Addison Wesley)
If you just want your server to listen on all addresses, then bind to
'0.0.0.0'
If you want to bind to several addresses (but not all of them) then you will
need to create a number of TCPServer objects, each binding to a single
address.
Regards,
Brian.
On Mon, Jan 06, 2003 at 01:58:12AM +0900, Edward Wilson wrote:
Hi,
In message “Re: Using TCPServer with multiple network cards” on 03/01/06, Edward Wilson web2ed@yahoo.com writes:
TCPServer binds to the first network card e.g. eth0; Java has this
same problem. Changing the “ip string” doesn’t change the network
card…at least from my experience.
Specifying the third and fourth argument to TCPSocket.open may help
you, I guess. They’re the local hostname (3rd) and the local service (4th).
matz.