title: How do I send and receive UDP packets in QT
body: <p>I am writing a small application in QT that sends a UDP packet broadcast over the local network and waits for a UDP responce packet from one or more devices over the network.</p>
  
  <p>Creating the sockets and sending the broadcast packet.</p>
  
  <pre><code>udpSocketSend = new QUdpSocket(this);
  udpSocketGet  = new QUdpSocket(this);
  bcast = new QHostAddress("192.168.1.255");
  
  udpSocketSend-&gt;connectToHost(*bcast,65001,QIODevice::ReadWrite);
  udpSocketGet-&gt;bind(udpSocketSend-&gt;localPort());
  connect(udpSocketGet,SIGNAL(readyRead()),this,SLOT(readPendingDatagrams()));
  
  QByteArray *datagram = makeNewDatagram(); // data from external function
  udpSocketSend-&gt;write(*datagram);
  </code></pre>
  
  <p>The application sends the packet properly and the response packet arrives but the <code>readPendingDatagrams()</code> function is never called. I have verified the packets are sent and received using Wireshark and that the application is listening on the port indicated in wireshark using Process Explorer.</p>