Could not read UDP packet. The situation is this: there is a device that sends UDP packets to the addresses 20.255.255.255. WireShark sees these packets, but I cannot receive a packet with a program written in QT. I receive a package like this:

connect(socket, SIGNAL(readyRead()), this, SLOT(listPort())); socket->bind(QHostAddress("20.0.0.1"), 36882); // Это код слота listPort() QByteArray datagram; QHostAddress sender; quint16 senderPort; while (socket->hasPendingDatagrams()) { datagram.resize(socket->pendingDatagramSize()); socket->readDatagram(datagram.data(), datagram.size(),&sender, &senderPort); } 

The address of the computer running the program written in QT 20.0.0.1 (as well as 192.168.1.10).

What could be the reason?

  • The connect function from which class? - sitevRu
  • In general, the reason is that this is essentially a multicast package, and you want to read packages specifically for host 20.0.0.1. But I don’t know how to fix this in the wonderful qt framework. An example for normal work in * nix. == I repent, of course, wrong. Yet here we are talking about some kind of broadcast (and not multicast). Then try to look here . - avp

1 answer 1

 socket->bind(QHostAddress("20.0.0.1"), 36882,QUdpSocket::ShareAddress); 
  • one
    Welcome to Stack Overflow in Russian ! Please try to leave a little more detailed answers. - aleksandr barakin
  • 2
    Please try to write more detailed answers. I am sure the author of the question would be grateful for your expert commentary on the code above. - Nicolas Chabanovsky