UDP block for simulink
Show older comments
Hi,
I am trying to use judp.m as a reference for building a simple udp receive block for simulink.
In simulink I am using matlab function block with the code below:
I am not very familiar with coder and would be thankful if I can get assistance in getting this block fixed.
Thanks
function mssg = judp(targetPort)
timeout = 5000;
packetLength = 10;
coder.extrinsic('java.io.*')
coder.extrinsic('java.net.InetAddress')
coder.extrinsic('java.net.DatagramSocket')
coder.extrinsic('java.net.DatagramPacket')
socket = java.net.DatagramSocket(targetPort)
socket.setSoTimeout(timeout)
socket.setReuseAddress(1);
packet = java.net.DatagramPacket(zeros(1,packetLength,'int8'),packetLength);
socket.receive(packet);
socket.close;
mssg = packet.getData;
mssg = mssg(1:packet.getLength);
inetAddress = packet.getAddress;
sourceHost = char(java.net.InetAddress.inetAddress.getHostAddress);
end
Answers (0)
Categories
Find more on Simulink Coder in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!