使用QUdpSocket:write(host :: broadcast)将多进程写入本地主机中的同一端口时会发生什么情况?

时间:2019-04-27 08:21:25

标签: c++ qt networking udp qtnetwork

我有一些发送程序进程,每个进程运行相同的发送程序,简而言之,这些发送程序将写入本地主机的相同端口,如:

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()));
    }
}

接收器进程(每个进程也运行相同的接收器程序)绑定到相同的端口,例如:

QUdpSocket

所有这些进程都在localhost中运行。

我在有两个发送器和三个接收器的机器上做了一些实验,看来接收器可以成功接收数据。

但是,当使用<script> function addValue(row) { //select all checkboxes with name userid that are checked var checkboxes = document.querySelectorAll("input[name='user_id[]']:checked") var values = ""; //append values of each checkbox into a variable (seperated by commas) for (var i = 0; i < checkboxes.length; i++) { values += checkboxes[i] .value + "," } //remove last comma values = values.slice(0, values.length - 1) //set the value of input box document.getElementById("studID").value = values; } //Above is the code to return value to the input=text. //Below is the code for check/uncheck all checkbox value function CheckUncheckAll() { var selectAllCheckbox = document.getElementById("checkUncheckAll"); if (selectAllCheckbox.checked == true) { var checkboxes = document.getElementsByName("user_id[]"); for (var i = 0, n = checkboxes.length; i < n; i++) { checkboxes[i].checked = true; var values = ""; //append values of each checkbox into a variable (seperated by commas) for (var i = 0; i < checkboxes.length; i++) { values += checkboxes[i] .value + "," } //remove last comma values = values.slice(0, values.length - 1) //set the value of input box } } else { var checkboxes = document.getElementsByName("user_id[]"); for (var i = 0, n = checkboxes.length; i < n; i++) { checkboxes[i].checked = false; var values = ""; for (var i = 0; i < checkboxes.length; i++) { values += "" } } } document.getElementById("studID").value = values; } </script> <table> <tr onclick="addValue(this);"> <td><input type="checkbox" name="user_id[]" value='User id' /></td> </tr> </table> <input type="text" id="studID"/> 将多进程写入本地主机中的同一端口时,我们可以对行为/数据做出任何假设吗?如果没有,会发生什么(例如,丢失一些数据包或接收到错误的数据)?

0 个答案:

没有答案