I'm writing an application that consists of two distinct programs. One (the client) sends UDP broadcast packets and the other (the server) logs any packets received.
The application is written in Qt - I've basically taken the UDP Multicast example and used it for the server. The client looks something like this:
QUdpSocket * socket = new QUdpSocket;
QByteArray datagram("This is a test!");
socket->writeDatagram(datagram.data(), datagram.size(),
QHostAddress::Broadcast, 45454);
The code actually does work - but very poorly. So few packets were arriving (I worked it out to about 3.1%). Now I totally understand that UDP doesn't guarantee that all of the packets will arrive without any getting dropped - but 3.1% seems ridiculous and has me wondering if I'm doing something wrong.
Both the client and server are running on a wireless network that is not being used for anything else. I tried sending packets at a slower and faster rate but it made no difference.
Client: Ubuntu 11.10 64-bit
Server: Ubuntu 12.04 64-bit
Edit: I've replaced QHostAddress::Broadcast
with QHostAddress("x.x.x.x")
(where x.x.x.x
is the IP address of the server) in the example above and none of the packets get dropped. So it seems like the problem is limited to broadcast packets.
Further edit: switching the client to Windows 7 results in only 9% packet loss (91% of the packets arrive).