Inquiry about IP address and port number for UDP Send and UDP Receive block
Show older comments
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
on 19 Sep 2024
0 votes
Hi @준호
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:
- "UDP Send" documentation - https://in.mathworks.com/help/releases/R2023b/instrument/udpsend.html
- "UDP Receive" documentation - https://in.mathworks.com/help/releases/R2023b/instrument/udpreceive.html
Hope this helps!
2 Comments
준호
on 20 Sep 2024
Malay Agarwal
on 20 Sep 2024
Edited: Malay Agarwal
on 20 Sep 2024
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.
Categories
Find more on Block Libraries in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
