UdpClient.JoinMulticastGroup Method (Int32, IPAddress)


The .NET API Reference documentation has a new home. Visit the .NET API Browser on docs.microsoft.com to see the new experience.

Adds a UdpClient to a multicast group.

Namespace:   System.Net.Sockets
Assembly:  System (in System.dll)

public void JoinMulticastGroup(
	int ifindex,
	IPAddress multicastAddr


Type: System.Int32

The interface index associated with the local IP address on which to join the multicast group.

Type: System.Net.IPAddress

The multicast IPAddress of the group you want to join.

Exception Condition

The underlying Socket has been closed.


An error occurred when accessing the socket. See the Remarks section for more information.

Before joining a multicast group, be sure the socket is bound to the port or endpoint. You can do this by calling one of the constructors that accepts a port or an endpoint as parameter.

The infindex parameter is used to identify a hardware interface on the same link.


There are several multicast address ranges to choose from. Refer to the IETF RFC 2375.


You cannot call JoinMulticastGroup on a UdpClient constructed without a specific local port (that is, using the UdpClient.UdpClient() or UdpClient.UdpClient(AddressFamily) constructor).

// Instantiate IPv6MulticastOption using another 
// overloaded constructor.
IPv6MulticastOption ipv6MulticastOption2 = new IPv6MulticastOption(group, interfaceIndex);

// Store the IPAdress multicast options.
group =  ipv6MulticastOption2.Group;
interfaceIndex = ipv6MulticastOption2.InterfaceIndex;

// Display the IPv6MulticastOption2 properties.
Console.WriteLine("IPv6MulticastOption.Group: [" + group  + "]");
Console.WriteLine("IPv6MulticastOption.InterfaceIndex: [" + interfaceIndex + "]");

// Join the specified multicast group using one of the 
// JoinMulticastGroup overloaded methods.
clientOriginator.JoinMulticastGroup((int)interfaceIndex, group);

.NET Framework
Available since 1.1
Return to top