I'm receiving UDP from another machine with the Instrument Toolbox UDP instrument. The objective is to have a timestamp from the sender act as a trigger in Matlab for a camera attached to my Windows PC, so that I can later sync the camera feed with the sender's other data (taking manually into account the latency of sending the message).
However, if the sender sends these timestamps very quickly (1000 Hz), I run into the problem that the datagrams get buffered somewhere, and if left to it the buffer grows over time as Matlab reads slower than the sender sends. Changing the UDP instrument's InputBufferSize doesn't help, as in my limited understanding that is only Matlab's own buffer, and the datagrams get queued somewhere in the OS's network stack. Looking with Wireshark, I see the latest datagrams coming from the sender, so there is some way to read these latest timestamps that I can't get to with Matlab.
Is there a way in Matlab to read the latest datagrams coming into my computer, instead of a FIFO approach? Or a way to make the socket's buffer smaller? I don't care if some or even most datagrams get discarded, as I only need the ones that Matlab is quick enough to read close to real time.
I realize changing the sender's speed would help, but this might still become an issue later.
Best Answer