Inquiry about IP address and port number for UDP Send and UDP Receive block

52 次查看(过去 30 天)
Hello all,
I have a question about the IP addresses and port numbers for the UDP Send and UDP Receive blocks. When sending and receiving data on the same PC, and using port 5002 to send data from MATLAB and port 5001 to receive data from external sources into MATLAB, how should I fill in fields 1 through 4?

回答(1 个)

Malay Agarwal
Malay Agarwal 2024-9-19,16:49
When working on a local computer, you only need to worry about the "Remote address" and "Remote port" parameters in both the blocks.
In the "UDP Send" block, the "Remote address" specifies the IP address you want to send data to and the "Remote port" specifies the port on which the receiver is listening or expecting data on. In the "UDP Receive" block, the "Remote address" specifies the IP address you want to receive data from and the "Remote port" specifies the port on which the sender will be sending data.
In your case, assuming you want the "UDP Send" block to send data to the "UDP Receive" block, the configuration should be as follows:
  • "UDP Send" block: Set the "Remote address" to "127.0.0.1" and the "Remote port" to the "Local port" of the "UDP Receive" block. This is because the "UDP Receive" block is expecting to receive data on its local port (the UDP receiver is listening on port 5002).
  • "UDP Receive" block: Set the "Remote address" to "127.0.0.1" and the "Remote port" to the "Local port" of the "UDP Send" block. This is because the "UDP Send" block is sending data over its local port and to receive data from the "UDP Send" block, the receiver must connect to that port.
I have attached an example model to the answer which shows this configuration.
If you'd like to learn more about networking including IP addresses and port numbers, refer to the following resource: https://www.iitk.ac.in/esc101/05Aug/tutorial/networking/overview/networking.html
Refer to the following resources for more information:
Hope this helps!
  2 个评论
준호
준호 2024-9-20,10:05
Hi Malay,
Thank you for a kind reply.
I tried as you commanded, but there is an error below.
It says that each socket address (protocol/network address/port) can only be used by one instance.
Malay Agarwal
Malay Agarwal 2024-9-20,12:46
编辑:Malay Agarwal 2024-9-20,12:47
Please make sure that the ports that you are using are not being used by any other services.
On Windows, launch an Administrator Command Window and use the following command:
netstat -anob
This will list all the ports that are being used on your system. Make sure your ports for the blocks are not in the list. If they are, use port numbers that are not in the list.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Direct Interface Communication in Simulink 的更多信息

标签

产品


版本

R2023b

Community Treasure Hunt

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

Start Hunting!

Translated by