Hi Greg, *IPAddress.Broadcast* is equivalent to 255.255.255.255 - which is equivalent to 'this network'. So the machine is not selecting 'this' network to your liking I guess.
>From Wikipedia: *The broadcast address for an IPv4 host can be obtained by performing a bitwise <http://en.wikipedia.org/wiki/Bitwise_operator> logical OR<http://en.wikipedia.org/wiki/Bitwise_operator#OR>operation between the bit complement <http://en.wikipedia.org/wiki/Bit_complement> of the subnet mask<http://en.wikipedia.org/wiki/Subnetwork> * and the host's IP address. *Example: to broadcast a packet to an entire IPv4 subnet using the private IP address <http://en.wikipedia.org/wiki/Private_IP_address> space 172.16.0.0/12, which has the subnet mask 255.240.0.0, the broadcast address is: 172.16.0.0 | 0.15.255.255 = 172.31.255.255.* *A special definition exists for the IP broadcast address 255.255.255.255. It is the broadcast address of the **zero network (0.0.0.0/0), which in Internet Protocol standards stands for **this network, i.e. the local network. Transmission to this address is limited by definition, in that it is never forwarded by the routers connecting the local network to the Internet.* For example if the subnet you want to broadcast to is 192.168.1 / 24 for example (subnet mast 255.255.255.0) you would need to do the bitwise logical OR between 192.168.1.0 | (11000000 10101000 00000001 00000000) or 192.168.1.0 | (00000000 00000000 00000000 11111111) or (0.0.0.255) ------------------------------------------------------------- (11000000 10101000 00000001 00000000) so the broadcast IP here is 192.168.1.255 This would ensure correct network card is used to send out the broadcast Cheers, jano On 13 December 2010 07:56, Greg Keogh <[email protected]> wrote: > Folks, I’ve got old code that sends UDP broadcasts like this simple > skeleton: > > > > UdpClient broadcaster = new udpClient(); > > IPEndPoint ep = new IPEndPoint(IPAddress.Broadcast, 8888); > > Broadcaster.Send(buffer, buffer.Length, ep); > > > > We have just found that if there are multiple network cards in the machine > then it’s unpredictably broadcasting on the wrong interface and the > listeners get nothing. I’m not sure how to code a fix for this. Do I need to > do this to get an IPAddress array and then put them all into the Send call? > Like this...? > > > > string hostname = Dns.GetHostName(); > > IPHostEntry he = Dns.GetHostByName(hostname); > > foreach (IPAddress addr in he.AddressList) > > { > > // Send with an endpoint set to each addr instead of > IPAddress.Broadcast? > > } > > > > I’m not sure if this is the correct technique. Any sockets boffins here > know this sort of thing? > > > > Cheers, > > Greg >
