Hi Mark,
I understand that you want to test if your udp port is receiving data or not. For this you can simply use two MATLAB sessions to test whether the udp port is receiving data or not.
For an example regarding the udp communication please refer to the following MATLAB documentation.
For the second question your code is fine and works perfectly.
Hope this helps.