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)

답변 (1개)

ag
ag 2025년 2월 5일

0 개 추천

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!

카테고리

도움말 센터File Exchange에서 Data Import and Analysis에 대해 자세히 알아보기

질문:

2021년 10월 6일

편집:

2025년 2월 5일

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by