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

Reply via email to