Ok, so if I simply write my object as 'one' datagram, the subscriber will be able to deserialize the bytes received.
void publishEvent(MyEvent const& e) {
// Add request-dependent data
out<< e;
writeDatagram(eventData.size(), eventData);
}
}
void onReadyRead() {
do {
eventData.resize(pendingDatagramSize());
readDatagram(eventData.data(), eventData.size());
// Get and handle received event data
MyEventData e;
in>> e;
} while (hasPendingDatagrams());
}
class Publisher : public QUdpSocket {
void publishEvent(MyEvent const& e) {
QByteArray eventData;
QDataStream out(&eventData, QIODevice::WriteOnly);
out.setVersion(QDataStream::Qt_4_8);
// Add request-dependent data
out<< e;
writeDatagram(eventData.size(), eventData);
}
}
class Subscriber : public QUdpSocket {
void onReadyRead() {
QByteArray eventData;
do {
eventData.resize(pendingDatagramSize());
readDatagram(eventData.data(), eventData.size());
QDataStream in(&eventData, QIODevice::ReadOnly);
// Get and handle received event data
MyEventData e;
in>> e;
} while (hasPendingDatagrams());
}
To copy to clipboard, switch view to plain text mode
The doc for QUdpSocket::writeDatagram() states that the number of bytes to be sent should not be larger than 512 bytes because in IP layer the data could be fragmented. But isn't the IP layer on the receiver side responsible for reassembilng the data and providing the data for the UDP layer as one datagram? IMHO if due to fragmentation a single IP packet is getting lost, the UDP datagram can not be reassembled and therefore the whole datagram will be lost.
best regards,
michael
Bookmarks