- udp - https://www.mathworks.com/help/instrument/udp.html
- udpport - https://www.mathworks.com/help/instrument/udpport.html
How to receive UDP packet
2 ビュー (過去 30 日間)
古いコメントを表示
In WireShark, receive this packet, but matlab is not work
%-- Send
u = udp('192.168.1.6', 'RemotePort', 4013, 'LocalPort', 4012);
fopen(u);
fwrite(u,65:74);
%-- Receive
u = udp('192.168.1.55', 'RemotePort', 4012, 'LocalPort', 4013);
fopen(u);
A = fread(u,10)
0 件のコメント
回答 (1 件)
ag
2025 年 2 月 5 日
Hi Sungcul,
To establish UDP communication in MATLAB, kindly ensure that the IP addresses and ports are correctly configured, with the sender and receiver having matching configurations. Open the UDP connection using "fopen" and close it with "fclose" to manage resources properly. Check that your network settings, including any firewalls, permit UDP traffic on the specified ports. Use separate udp objects for sending and receiving data to avoid conflicts. Implement "try-catch" blocks to handle any errors that might occur during data transmission. When using "fwrite" and "fread", specify data types explicitly to ensure the data is handled correctly.
The below code snippet illustrates the steps:
% Send
sender = udpport('192.168.1.6', 'RemotePort', 4013, 'LocalPort', 4012);
fopen(sender);
try
fwrite(sender, 65:74, 'uint8');
catch ME
disp(ME.message);
end
fclose(sender);
delete(sender);
% Receive
receiver = udpport('192.168.1.55', 'RemotePort', 4012, 'LocalPort', 4013);
fopen(receiver);
try
A = fread(receiver, 10, 'uint8');
disp(A');
catch ME
disp(ME.message);
end
fclose(receiver);
delete(receiver);
For more details, please refer to the following MathWorks documentations:
Hope this helps!
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!