MulticastOption in C# sockets

The MulticastOption class sets IP address values when joining or leaving an IP multicast group.

The following examples joins the default IP interface to an IP multicast group. It assumes that groupIP is an IPAddress instance that has been set to the IP multicast group address in the range 224.0.0.0 to 239.255.255.255.

Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp ); 
sock.SetSocketOption(SocketOptionLevel.IP, 
    SocketOptionName.AddMembership, 
    new MulticastOption( groupIP ));

Enjoyed this post? Share it!

 

Leave a comment

Your email address will not be published.