UdpClient.EnableBroadcast Property

Definition

Gets or sets a Boolean value that specifies whether the UdpClient may send broadcast packets.

C#
public bool EnableBroadcast { get; set; }

Property Value

true if the UdpClient allows sending broadcast packets; otherwise, false. The default is false.

Examples

The following code example shows the use of the EnableBroadcast property.

C#
public static void GetSetEnableBroadcast(UdpClient u)
{
    // Set the Broadcast flag for this client.
    u.EnableBroadcast = true;
    Console.WriteLine("EnableBroadcast value is {0}",
        u.EnableBroadcast);
}

Remarks

Broadcasting is limited to a specific subnet. You can broadcast to your local subnet by sending a packet to 255.255.255.255; or, you can use the directed broadcast address, which is the network portion of an Internet Protocol (IP) address with all bits set in the host portion. For example, if your IP address is 192.168.1.40 (a Class C address, with the network portion as the first three octets, and the host portion is the last octet), your directed broadcast address is 192.168.1.255.

Applies to

Product Versions
.NET Core 1.0, Core 1.1, Core 2.0, Core 2.1, Core 2.2, Core 3.0, Core 3.1, 5, 6, 7, 8, 9, 10
.NET Framework 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
.NET Standard 1.3, 1.4, 1.6, 2.0, 2.1