UDP Troubleshooting Send Working Receive Not

10 次查看(过去 30 天)
I'm working on using udp to communicate between a computer and an arduino-like device. I've written code that works using the matlab udp interface on my computer running matlab2014b, but when I switch to my second computer also running matlab2014b the code no longer works... Specifically just the read functionality of the udp interface doesn't work... Here is a super simplified version of my code:
function testUDP
%echoudp('on',2390);
udpClient = udp('18.111.59.194',2390, 'LocalPort', 5000);
u.InputBufferSize = 1000000;
u.DatagramTerminateMode = 'on';
bytesToread = 44*30 + 32;
fopen(udpClient);
pause(3);
fprintf(udpClient, 'Connection made.');
disp(udpClient);
for m= 1:25
data = fread(udpClient,bytesToread);
end
fclose(u);
end
The interesting thing is that the send functionality is working.. I'm able to confirm that my udp server (arduino-like device) is receiving the simple message that the matlab script on the second computer sends. After that the udp server gets the ip address of the second computer and starts to send data back to the second computer which I can confirm makes it to the second computer with wireshark. However the matlab script isn't picking up the data and consistently times out on its read function.
Anyone have any suggestions on what might be going wrong? I've already looked at this page Troubleshooting UDP interface and it didn't help. I'm confused as to why the code works on one computer and not the other. Only difference I can tell exists between the two computers is that one is running windows 10 and the other is running windows 7. <- I'm inclined to think that this shouldn't be an issue unless matlab needs extra permission to received udp data?
Any suggestions would be helpful thanks :)

回答(1 个)

Pulkit Goel
Pulkit Goel 2020-6-25
This issue may arise due to firewall blocking udp packets you are trying to recieve. You can try making some ports bypass your firewall using following steps:
Windows Defender Firewall > Inbound Rules > New Rule > Select Port > Next > Select UDP > Specify Porr of your Choice (you may select all, which is not recommended) > Allow the Connection > Next > Next > Enter name and description (for your convininence) > Finish
Follow same for Outbound Rules.

类别

Help CenterFile Exchange 中查找有关 Loops and Conditional Statements 的更多信息

产品

Community Treasure Hunt

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

Start Hunting!

Translated by