0
votes

I am having great difficulty receiving a UDP broadcast in Python. A device connected to PC via ethernet broadcasts messages on a specific address and port. I have tried numerous multicast python examples found online but I can never receive the data. Using wireshark I can see the UDP broadcasts are reaching the PC.

Wireshark capture

I have tried on OSX and Linux and neither work. I can only assume the messages are not being received because the device uses a non standard UDP structure, i.e. no checksum validation etc

Any ideas on how to receive these UDP broadcasts?

Thanks!

Edit: In the simplest form the current code would be:

from socket import *
s=socket(AF_INET, SOCK_DGRAM)
s.bind(('239.255.60.60',4876))
m=s.recvfrom(1024)
print (m[0])

However I have tried additional multicast examples such as Multicast in Python and am yet to be able to receive ANYTHING!

2
Please add a minimal, complete and verifiable example. stackoverflow.com/help/mcverfkortekaas
Normally, your operating system network stack will catch IP packets for you; if you want to work with raw IP you should give us much more details (what OS, what version of Python, and please show the fine code).wazoox
Im using Python3 on Ubuntu, I believe I am going to have to work with raw sockets and start from the ground up...user2818700

2 Answers

0
votes

You are not receiving the broadcast because you are not using the broadcast address.

Either use:

s.bind(('',4876))

Or the correct broadcast address for your ip.

0
votes

Ok found the answer, rather isolated to this scenario and kicking myself for overlooking it.

The device connected via ethernet was waiting to be assigned an IP address!! Wireshark must capture network traffic at a lower level than python.

Anyway manually assigned the device an ip address and now it is working. Much relief.