Using python, network programming is very simple.
There are several networking library already available, so you can think to use one of this library to do the work.
My favourite libraries are the following:
- py-multicast 1.4
Anyway, since multicast traffic is no different than regular UDP except for the IP address. We are going to take a look at the standard socket library.
It is simple to use.
The sender program will open a new datagram socket and then it will configure the socket to use multicast with a time to live of 32 hops (line 7).
At line 8 the program will send the "Hello World" Message to the multicast group
The receiver program will create a new datagram socket then it will bind the socket to the Multicast group and port, last it will loop forever waiting from multicast data on that socket. Any received string will be printed out. (lines 14-15)