I am using a QLocalSocket to transfer a Measurement struct at intervals to clients from a server program.
I set up the block and QDataStream then:
out.writeRawData(data, sizeof(Measurement));
out.device()->reset();
Then for each registered client:
clients_.at(i)->write(block);
clients_.at(i)->flush();
Then at the other end on signal readyRead():
in.readRawData((char *) data, sizeof(Measurement));
What I want to happen is that if the client is not ready to receive when the measurement is sent it will skip a reading.
At the moment I get:
send 3
read 3
send 4
send 5
read 4
How can I get:
send 3
read 3
send 4
send 5
read 5
If the server has written something into the pipe (and
flush()ed on top), then the client simply must read it out of the pipe, to be able to access the subsequent messages. If you don’t want to do anything with the message you can simplyin.skipRawData(sizeof(Measurement))on the client side. But if you want to avoid client getting ANY data, then you must prevent server from sending anything altogether. So some sort of congestion control. From the top of my head, i would let the client(s) signal something likemessageAcknowledgeReadyForNext()ornotReadyToReceive()and in theclients_iteration cycle, let’s skip those clients which has sent not ready (and also such which are not known as sent at least one acknowledge).