I have some sender processes, each of them running the same sender program, in short, these sender write to the same port in localhost like:
udpSocket->writeDatagram(datagram, QHostAddress::Broadcast, 45454);
The receiver processes, each of them also running the same receiver program, bind to the same port, like:
udpSocket->bind(45454, QUdpSocket::ReuseAddressHint); // windows system
connect(udpSocket, SIGNAL(readyRead()),
this, SLOT(processPendingDatagrams()));
// ...
void Receiver::processPendingDatagrams()
{
QByteArray datagram;
while (udpSocket->hasPendingDatagrams()) {
datagram.resize(int(udpSocket->pendingDatagramSize()));
udpSocket->readDatagram(datagram.data(), datagram.size());
statusLabel->setText(tr("Received datagram: \"%1\"")
.arg(datagram.constData()));
}
}
All these processes run in localhost.
I did do some experiment on my machine, with two senders and three receivers, it seems that the receiver can receive data success.
But can we make any assumption about the behavior/data when multi-process write to the same port in localhost using QUdpSocket
? If not, what might happen(for example, missing some data packet or wrong data received)?