Clear Filters
Clear Filters

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

55 views (last 30 days)
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?

Answers (1)

Malay Agarwal
Malay Agarwal on 19 Sep 2024 at 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 Comments
준호
준호 on 20 Sep 2024 at 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 on 20 Sep 2024 at 12:46
Edited: Malay Agarwal on 20 Sep 2024 at 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.

Sign in to comment.

Categories

Find more on Direct Interface Communication in Simulink in Help Center and File Exchange

Products


Release

R2023b

Community Treasure Hunt

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

Start Hunting!