Multicast (UDP)

Related pages: Unicast (UDP / TCP) Q&A

Why multicast Multicast on LAN Multicast on WAN What is multicast Multicast Client Multicast Server   Programming Documentation Network Numbering Documentation

Why multicast

Multicast is useful when you have to transmit the SAME message to more than one host.

Usually the client that send multicast does not know how many servers will really receive his packets.
When talking about client-server in network, the client sends the request, the server receives the request and might send back an answer.

Since multicast is based UDP, the transmission is by default not reliable.

The advantage of using multicast instead of broadcast is that only interested hosts will get the message, and the message should be transmitted only once for many clients (saves a lot of bandwith).
Another advantage is the possibility of sending packets larger than interface MTU

Multicast on LAN

This is topic is quite complex, but we can for simplicity devide LANs in 3 kind:

  1. LAN with hubs only
  2. LAN with switches without IGMP support
  3. LAN with switches with IGMP support

The first 2 types of LANs are the easiest to explain, since the behaviour for multicast is exactly the same; multicast is transmitted over all network segments.

In the third case where the LAN has IGMP aware switches, and IGMP support is enabled, multicast packets will be transmitted only on segments where hosts have requested it. Other segments will not see this kind of traffice until one of the hosts requests it.
Of course packets sent to could be observed on all segments, since these addresses have a special meaning ( Reserved Multicast IP addresses)

Multicast on IPv6

IPv6 multicast (FF00::/8) addressing is defined in this document IPv6 address range, broadcast in IPv6 is a special multicast, address FF02:0:0:0:0:0:0:1 is IPv6 form of in IPv4, it targets all hosts in local network (FF02::/16).

Multicast on WAN

... Still Working ....

What is multicast

Multicast is a kind of UDP traffic similar to BROADCAST, but only hosts that have explicitly requested to receive this kind of traffic will get it. This means that you have to JOIN a multicast group if you want to receive traffic that belongs to that group.

IP addresses in the range to ( Class D addresses) belongs to multicast. No host can have this as IP address, but every machine can join a multicast address group.

Before you begin

Sample code

This is a sample multicast server without error handling
Comments on code
----------- cut here ------------------

----------- cut here ------------------
This is a sample multicast client without error handling
----------- cut here ------------------

----------- cut here ------------------

Be careful because ...

Possible differences might be noted between different flavour of Unix.

In some implementation you might need to call setsockopt before calling bind.

Note that we do not BIND the server to a specific interface, but we JOIN the multicast group ( IP_MULTICAST_JOIN ) on a specific interface

The same appens on the client side, we do not BIND to an interface but we set the transmitting interface with IP_MULTICAST_IF.

IP Classes

Class Name Address Bits From ... To Pourpose
Class A 0 - Public IP address
Class B 10 - Public IP address
Class C 110 - Public IP address
Class D 1110 - Multicast IP Addresses
Class E 11110 - Reserved

Programming Documentation

If you are interested in getting more details about socket programming have a look at

Network Numbering Documentation

For more details about IP address space usage see IANA
Reserved Multicast IP addresses
IANA assigned Numbers
last modification 13 December 2003