I successfully subscribed and received a packet from a multicast stream, by the following:
socket = java.net.MultiSocket(streamPort);
socket.joinGroup(java.net.InetAddress.getByName(streamIP));
socket.setReuseAddress(1);
packet = java.net.DatagramPacket(zeros(1, intmax('uint16'), 'int8'), intmax('uint16'));
socket.receive(packet);
socket.leaveGroup(InetAddress.getByName(streamIP));
socket.close;
msg = packet.getData;
msg = msg(1:packet.getLength);
This was essentially lifted from judp
availble on the MathWorks File Exchange.
I am still looking for a way to get some equivalent of a DatagramReceivedFcn
- right now it looks like the socket.receive
call is blocking until it times out. I can use timer
objects to fire the "callback" on a regular basis but that's of course not the same as having a DatagramReceivedFcn
.