JoinMulticastGroup Method (IPAddress)
Collapse the table of content
Expand the table of content

UdpClient.JoinMulticastGroup Method (IPAddress)


Adds a UdpClient to a multicast group.

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

member JoinMulticastGroup : 
        multicastAddr:IPAddress -> unit


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.


The IP address is not compatible with the AddressFamily value that defines the addressing scheme of the socket.

The JoinMulticastGroup method subscribes the UdpClient to a multicast group using the specified IPAddress. After calling the JoinMulticastGroup method, the underlying Socket sends an Internet Group Management Protocol (IGMP) packet to the router requesting membership to the multicast group. The multicast address range is to If you specify an address outside this range or if the router to which the request is made is not multicast enabled, UdpClient will throw a SocketException. If you receive a SocketException, use SocketException.ErrorCode to obtain the specific error code. Once you have obtained this code, you can refer to the Windows Sockets version 2 API error code documentation in MSDN for a detailed description of the error. Once the UdpClient is listed with the router as a member of the multicast group, it will be able to receive multicasted datagrams sent to the specified IPAddress.


You must create the UdpClient using the multicast port number; otherwise, you will not be able to receive multicasted datagrams. Do not call the Connect method prior to calling the JoinMulticastGroup method, or the Receive method will not work. You do not need to belong to a multicast group to send datagrams to a multicast IP address.

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

To stop receiving multicasted datagrams, call the DropMulticastGroup method and provide the IPAddress of the group from which you would like to withdraw.


In the IPv6 case, there are several multicast address ranges you can choose from. Please, refer to 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 demonstrates how to join a multicast group by providing a multicast address.

No code example is currently available or this language may not be supported.

Universal Windows Platform
Available since 10
.NET Framework
Available since 1.1
Return to top
© 2016 Microsoft