From: Brian Candler Date: 2003-01-06T08:33:37+09:00 Subject: Re: Using TCPServer with multiple network cards On Mon, Jan 06, 2003 at 01:58:12AM +0900, Edward Wilson wrote: > 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.