UdpClient.JoinMulticastGroup Method (IPAddress, IPAddress)

Adds a UdpClient to a multicast group.

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

public void JoinMulticastGroup(
	IPAddress multicastAddr,
	IPAddress localAddress


Type: System.Net.IPAddress

The multicast IPAddress of the group you want to join.

Type: System.Net.IPAddress

The local IPAddress.


The underlying Socket has been closed.


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

Before you join a multicast group, be sure that 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.


There are several multicast address ranges to choose from. You can find them in the IETF RFC 2375.


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

The following code example shows the use of the JoinMulticastGroup method.

// Subscribe to a multicast group. 
public static void DoJoinMulticastGroup(UdpClient u, string mcast)
    IPAddress[] multicastAddress = Dns.GetHostAddresses(mcast);

    Console.WriteLine("Joined multicast Address {0}",

.NET Framework

Supported in: 4.5.2, 4.5.1, 4.5, 4, 3.5, 3.0, 2.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Was this page helpful?
(1500 characters remaining)
Thank you for your feedback
© 2014 Microsoft