Skip to content Skip to sidebar Skip to footer

Python Udp Broadcast Not Sending

I am trying to UDP broadcast from a Python program to two LabView programs. I cannot seem to get the broadcast to send and I am not sure where my socket initialization is wrong, br

Solution 1:

You do not need to connect() to a UDP socket, instead:

cs.sendto(data, ('255.255.255.255', 5455))

EDIT: This seems to work for me:

from socket import *
cs = socket(AF_INET, SOCK_DGRAM)
cs.setsockopt(SOL_SOCKET, SO_REUSEADDR, 1)
cs.setsockopt(SOL_SOCKET, SO_BROADCAST, 1)
cs.sendto('This is a test', ('255.255.255.255', 54545))

On another machine I ran tcpdump:

tcpdump-ieth1port54545-XXlisteningoneth1,link-typeEN10MB(Ethernet),capturesize65535bytes14:04:01.797259IP10.22.4.45.33749>255.255.255.255.54545:UDP,length140x0000:fffffffffffff0def1c48aa60800 4500..............E.0x0010:002a0000 4000 4011 2c810a16042dffff.*..@.@.,....-..0x0020:ffff83d5d5110016 fe385468 6973 2069.........8This.i0x0030:7320 6120 7465 7374 0000 0000            s.a.test....

You can see the text in the payload. As well as the broadcast Ethernet and IP dst addrs.

Post a Comment for "Python Udp Broadcast Not Sending"