I am subscribing to a multicast UDP stream in MATLAB. This can't done done natively, so instead I am using a java.net.MulticastSocket
object. Each UDP packet is tagged with some meta-data, in particular a sequence count. Every time my data source sends a UDP packet, that sequence count is incremented.
Here's my skeleton code:
s = java.net.MulticastSocket(50001);
s.setSoTimeout(15000);
s.setReuseAddress(1);
s.setReceiveBufferSize(32768);
s.joinGroup(java.net.InetAddress.getByName('239.255.0.4'));
p = java.net.DatagramPacket(zeros(1, 1600, 'int8'), 1600);
ii = 1;
d = cell(10000,1);
while ii < 10000
s.receive(p);
d{ii} = p.getData;
d{ii} = d{ii}(1:p.getLength);
ii = ii + 1;
end
Once I catch all the data, I can post-process it; that bit isn't important.
After catching 10,000 packets like this, I look at the sequence count and it turns out I'm missing packets. That's fair; this is UDP after all so there's no guarantee of receipt of traffic. However, what's really interesting is I'm only receiving every 256th packet:
sequenceCnt =
...
56637
56893
57149
57405
57661
57917
58173
58429
58685
58941
59197
59453
...
I have Wireshark running and watching the data stream coming in, and the packets are definitely incrementing. So my computer is seeing the multicast stream in its entirety (i.e., not dropping packets because UDP doesn't guarantee delivery), but this little MATLAB/Java code is unable to keep up with the stream.
Any idea what is going on? I have basically zero Java experience, so any help would be appreciated.