我正在使用QT。我需要广播数据,所以我尝试使用QUdpSocket
. 但数据可能太大(writeDatagram
QUdpSocket::error
返回后DatagramTooLargeError
)。所以我拆分数据并writeDatagram
多次调用这些部分。但是Received socket只接收一次数据,只有第一个数据包。接收代码是
connect(&m_socketReceiver, &QUdpSocket::readyRead, this, &LocalNetSharing::onDataRead);
void LocalNetSharing::onDataRead()
{
while (m_socketReceiver.hasPendingDatagrams())
{
QByteArray datagram;
datagram.resize(m_socketReceiver.pendingDatagramSize());
m_socketReceiver.readDatagram(datagram.data(), datagram.size());
//process data
}
}