0

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).

Nathan Osman
  • 71,149
  • 71
  • 256
  • 361
  • It could be in how you configure the UDP socket. Could you show code for that? –  Jun 18 '12 at 18:54
  • @Michael: I've added the code - but all it consists of is a single line that creates the actual socket. – Nathan Osman Jun 18 '12 at 19:12
  • I don't see you joining the [multi-cast group](http://en.wikipedia.org/wiki/IP_multicast) in the client code above. Was this intentional? –  Jun 18 '12 at 19:53
  • @Michael: This application is using IP broadcasting, which is different from IP multicasting. – Nathan Osman Jun 18 '12 at 19:55
  • @Michael And you don't have to join a multicast group to send to it. – user207421 Jun 19 '12 at 21:35
  • @EJP I'm aware you don't *need* to join the multicast group, but it may give higher reliability in transmission if for no other reason than most routers block broadcast traffic by default. Also, the example program linked in the question is for a multicast client. –  Jun 19 '12 at 21:45
  • @Michael Joining the multicast group does not improve the reliability of sending. All it does is cause group traffic to come your way, which may even *decrease* reliability. And this router isn't blocking broadcasts at all. – user207421 Jun 19 '12 at 22:58
  • Blocking broadcast packets would cause a number of protocols to fail. – Nathan Osman Jun 20 '12 at 00:13
  • @NathanOsman: I'm having exactly the same problem, now at Qt 5.5.0. `QUdpSocket`s eventually stall completely after receiving some broadcast datagrams, no error, nothing. I suppose this is a bug. – alecov Oct 15 '15 at 17:30

0 Answers0