Skip to content

Regarding the issue of the UdpClient.EnableBroadcast property #118055

@296370493

Description

@296370493

Description

When I was using UdpClient, I found that even when UdpClient.EnableBroadcast was set to false, it could still successfully send data via broadcast.

Reproduction Steps

using System.Net;
using System.Net.Sockets;
using System.Text;

namespace ConsoleApp1
{
    internal class Program
    {
        static void Main(string[] args)
        {
            using (var udpClient = new UdpClient(8080))
            {
                udpClient.EnableBroadcast = false;
                var ipEndPoint = new IPEndPoint(IPAddress.Broadcast, 8081);
                byte[] data = Encoding.UTF8.GetBytes("test");
                udpClient.Send(data, data.Length, ipEndPoint);
            }
        }
    }
}

Expected behavior

When UdpClient.EnableBroadcast is set to false, shouldn't an exception occur?

Actual behavior

When UdpClient.EnableBroadcast is set to false, data can be sent normally via broadcast.

Regression?

No response

Known Workarounds

No response

Configuration

.NET version:.NET 8
System: Windows 10 22H2

Other information

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-System.NetuntriagedNew issue has not been triaged by the area owner

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions