Adds a System.Net.Sockets.UdpClient to a multicast group with the specified Time to Live (TTL).
- multicastAddr
- The System.Net.IPAddress of the multicast group to join.
- timeToLive
- The Time to Live (TTL), measured in router hops.
The UdpClient.JoinMulticastGroup(System.Net.IPAddress) method subscribes the System.Net.Sockets.UdpClient to a multicast group using the specified System.Net.IPAddress. After calling the UdpClient.JoinMulticastGroup(System.Net.IPAddress) method, the underlying System.Net.Sockets.Socket sends an Internet Group Management Protocol (IGMP) packet to the router requesting membership to the multicast group. The multicast address range is 224.0.0.0 to 239.255.255.255. If you specify an address outside this range or if the router to which the request is made is not multicast enabled, System.Net.Sockets.UdpClient will throw a System.Net.Sockets.SocketException. If you receive a System.Net.Sockets.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. The timeToLive parameter specifies how many router hops will be allowed for a multicasted datagram before being discarded. Once the System.Net.Sockets.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 System.Net.IPAddress.
You must create the System.Net.Sockets.UdpClient using the multicast port number otherwise you will not be able to receive multicasted datagrams. Do not call the UdpClient.Connect(string, int) method prior to calling the UdpClient.JoinMulticastGroup(System.Net.IPAddress) 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 as parameter a port or an endpoint.
To stop receiving multicasted datagrams, call the UdpClient.DropMulticastGroup(System.Net.IPAddress) method and provide the System.Net.IPAddress of the group from which you would like to withdraw.
You cannot call erload:System.Net.Sockets.UdpClient.JoinMulticastGroup on a System.Net.Sockets.UdpClient constructed without a specific local port (that is, using the UdpClient.#ctor or UdpClient.#ctor(AddressFamily) constructor).