I was just playing around with a UdpClient
and noticed setting UdpClient.EnableBroadcast
to true
or false
doesn't have any (side)effect, I am able to broadcast with it either way:
using (UdpClient client = new UdpClient())
{
byte[] data = Encoding.ASCII.GetBytes("Hello");
while (true)
{
client.Send(data, data.Length, new IPEndPoint(IPAddress.Broadcast, 45678));
Console.WriteLine("sent");
Console.ReadKey();
}
}
The MSDN page is rather vague on this, but it sounds like it should cause an exception if you broadcast with the property set to false
:
Gets or sets a Boolean value that specifies whether the UdpClient may send or receive broadcast packets. ... true if the UdpClient allows broadcast packets; otherwise, false. The default is false.
Not a critical issue, but it just made me wonder. Is this a bug or is the property just there so you can refer to it later and find out whether you are meant to broadcast with it or not?