Skip to content

UDP multicast support (JoinMulticastGroup / LeaveMulticastGroup) #18

@suleymanbyzt

Description

@suleymanbyzt

IP multicast allows sending a single datagram to multiple receivers simultaneously at the network level — the OS/network handles fan-out instead of the application. Essential for service discovery, real-time data feeds, and LAN gaming.

Depends on #16 (StormUdpServer) and #17 (StormUdpClient).

Proposed API

Server — multicast send:

var udp = new StormUdpServer(new UdpServerOptions
{
    EndPoint = new IPEndPoint(IPAddress.Any, 9000),
});

await udp.StartAsync();

// Send to multicast group (network-level fan-out)
await udp.MulticastAsync(
    new IPEndPoint(IPAddress.Parse("239.255.0.1"), 9000), data);

Client — multicast receive:

var client = new StormUdpClient(new UdpClientOptions
{
    EndPoint = new IPEndPoint(IPAddress.Any, 9000),
    ReuseAddress = true,
});

client.OnDataReceived += async data =>
{
    Console.WriteLine($"Multicast: {data.Length} bytes");
};

await client.StartAsync();
client.JoinMulticastGroup(IPAddress.Parse("239.255.0.1"));

// Later
client.LeaveMulticastGroup(IPAddress.Parse("239.255.0.1"));

Notes

  • IPv4: SocketOptionLevel.IP + MulticastOption
  • IPv6: SocketOptionLevel.IPv6 + IPv6MulticastOption
  • ReuseAddress = true required for multiple receivers on same port
  • Server MulticastAsync is a convenience over SendToAsync with a multicast address
  • Could integrate with StormSocket Groups in the future: server.Groups.JoinMulticast("239.255.0.1:9000") — but keep it simple first

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions