Get pnet to do UDP blocking

Pnet is a MEX-file-based toolbox for Octave/MATLAB. The help instructions would lead you to believe that UDP reads block by default, but this didn’t work for me: I had to specify a timeout. You can specify Inf, but given that you can’t ctrl-c out of a program whilst the MEX part is running, I’d recommend choosing a reasonable value (like 20, = 20 seconds).

Here’s a simple example:
pnet('closeall');
sock=pnet('udpsocket',10000);
pnet(sock,'udpconnect','127.0.0.1',1000);
pnet(sock,'setreadtimeout',20)
pnet(sock,'printf','*r');
pnet(sock,'writepacket');
pnet(sock,'readpacket');
data = pnet(sock, 'read')