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
)

Parameters

multicastAddr
Type: System.Net::IPAddress^

The multicast IPAddress of the group you want to join.

localAddress
Type: System.Net::IPAddress^

The local IPAddress.

Exception Condition
ObjectDisposedException

The underlying Socket has been closed.

SocketException

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.

System_CAPS_noteNote

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

System_CAPS_noteNote

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.
static void DoJoinMulticastGroup( UdpClient^ u, String^ mcast, String^ local )
{
   array<IPAddress^>^ multicastAddress = Dns::GetHostAddresses( mcast );

   u->JoinMulticastGroup( multicastAddress[0] );
   Console::WriteLine(  "Joined multicast Address {0}", multicastAddress );
}

.NET Framework
Available since 2.0
Return to top
Show: