Python multicasting UDP wireshark

https://www.wireshark.org/

A multicast address is a logical identifier for a group of hosts in a computer network that are available to process datagrams or frames intended to be multicast for a designated network service. Multicast addressing can be used in the link layer (layer 2 in the OSI model), such as Ethernet multicast, and at the internet layer (layer 3 for OSI) for Internet Protocol Version 4 (IPv4) or Version 6 (IPv6) multicast.

 

Point-to-point connections handle a lot of communication needs, but passing the same information between many peers becomes challenging as the number of direct connections grows. Sending messages separately to each recipient consumes additional processing time and bandwidth, which can be a problem for applications such as streaming video or audio. Using multicast to deliver messages to more than one endpoint at a time achieves better efficiency because the network infrastructure ensures that the packets are delivered to all recipients.

Multicast messages are always sent using UDP, since TCP requires an end-to-end communication channel. The addresses for multicast, called multicast groups, are a subset of regular IPv4 address range (224.0.0.0 through 230.255.255.255) reserved for multicast traffic. These addresses are treated specially by network routers and switches, so messages sent to the group can be distributed over the Internet to all recipients that have joined the group.

Multicast groups is used for audio / multimedia, want to send same thing to a large group of people.

Multicastgroup is really just an IP, it just happens to fall in adr class of IP adr that indicats that is is a multicast adr.
We need to be able to multicast on port, and we use the AF_INET (Internet family), SOCK_DGRAM and specify socket.IPPROTO_UDP)

Lets verify this with wireshark.

import socket
mgrp = “224.1.1.2”
mport = 5555
sock = socket.socket(socket.AF_INET, socket.SOCK_DGRAM, socket.IPPROTO_UDP)
sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
for i in range(1, 3):
sock.sendto(b”This is a multicast messages to all who listen”, (mgrp, mport))
print(“Multicast msg sent”)
Now lets send some data and check it:
And there we have our multicast message in wireshark, great.
Scroll to Top