I have an application defined by software that sends UDP packets to a port that tell listeners what frequency and demodulation mode are set (among other things).
I wrote a demo python client (code below) that listens on the port and uploads information to the appropriate packages on the console.
They work under OSX 10.6, Snow Leopard. They work there.
I have a question / question: the Python application must be running before the radio application or it claims that the port is already in use (ERRNO 47) during the binding, and I do not understand why. The radio application broadcasts UDP; Of course, I want to accommodate a few listeners - which is the idea of broadcasting, or at least that's what I thought.
So, here is the Python code (the indentation is a bit confused due to the really stupid indentation of “make-it-code”, but I assure you):
#!/usr/bin/python import select, socket
For reference, here is a Qt code that sends a UDP message:
Setup:
bcast = new QHostAddress("192.168.1.255"); if (bcast) { udpSocketSend = new QUdpSocket(0); if (udpSocketSend) { udpSocketSend->bind(*bcast, txudp); } }
Broadcast:
if (udpSocketSend) { QByteArray *datagram = new QByteArray(1024,0); // datagram is full of zeroes strcpy(datagram->data(),msg); // except where text message is in it at beginning udpSocketSend->writeDatagram(*datagram, QHostAddress::Broadcast,txudp); // send }
fyngyrz
source share