Hi Everyone,
as stated in the subject, I am having some issues sending data. I have to create a loop, which sends the data 2 or more times for the listener to receive. Basically, I create a for loop, in which I send the same set of data across the network, however, on the first iteration in the loop, the listener receives nothing. Starting at the second iteration and every iteration after, I receive everything sent.
Is that a QoS problem, or would that be something different? I tried default qos for the data writer and reader, as well as set the same reader and writer to RELIABILITY.
I had the same problem. If you look at my previous post from yesterday:
https://community.rti.com/forum-topic/check-if-datawriter-ready-write
The issue is that the DataWriter takes time to set up, and if you call its write() method too soon it just returns without doing anything. Hence when you call the write() in a loop it will work, because by the 2nd or 3rd time round, the Writer will have constructed itself. I found if the publisher and subscriber were on the same machine, this didn't happen because the Writer can be created much faster.
Pretty bad design that - write() should at least return an error code when this happens (but it's void), or be a blocking call.
I put in a temporary fix by adding a 2 second sleep after creating the Writer and before the first write(). AFAIK subsequent writes should go through.
As I mentioned this is not a good solution, and I have asked if anyone knows of a way to check if the Writer is ready to write. No replies as of yet, but keep an eye on it. Hopefully it will fix your problem too.
Note that subsequent comments on the other thread clarify that the write() is not actually failing. The DataWriter has not yet discovered the DataReader.
Greenbolt,
Have you tried setting the Durability QoS to Transient Local?
This means that any late joining DataReaders will be sent samples which they have not yet received. For this to take effect you would need to add the following QoS snippet to both the DataReader and DataWriter QoS:
<durability>
<kind>TRANSIENT_LOCAL_DURABILITY_QOS</kind>
</durability>
This QoS policy will cause the DataWriter to resend the samples which are in its cache (the size of which is configured using the History QoS) to DataReaders which have not yet received them.
The reason which I think this might help you is that I suspect your DataWriter is writing before Discovery has completed (i.e., the DataReader is a "late joiner"). With Transient Local durability, the DataWriter will resend any missed samples to the DataReader.
Let me know if this helps your use-case,
Sam
Sam,
thank you for the answer. Unfortunately, in my use-case, I can not have any data in the cache.
Is the discovery done each time I try to send a message? Or only when my DataReaderListener and then the discovery should be set and good to go? I always start my DataReaderListener first, before I start the Writer. I will test your QoS settings though and see if it changes things. I will keep you updated!
Discovery is a separate process from sending samples. Once a pair of Participants complete the endpoint phase of Discovery, they know about each other's entities (DataWriters and DataReaders) until they lose Liveliness (or one notifies the other of its impending shutdown).
Can you elaborate on "I can not have any data in the cache"? Are you aware that instances you no longer need can be disposed and autopurged?
I was not aware of the fact that instances can be disposed and autopurged. But I am now, thank you for that.
I managed to solve my problem. It's nearly too embarassing to tell. I forgot to add a loop which checks if the writers publication matches status count is < 1. After I did that, everything worked just fine. I also figured out how to send data in a new thread to not block any UI interaction.
Thank you everybody for your help!