Main Content

UDP Receive

Receive UDP packets

Add-On Required: This feature requires the Simulink Support Package for Android Devices add-on.


Simulink Support Package for Android Devices / Communication

  • UDP Receive block


Receive UDP packets from another UDP host on the same local network.

The UDP Receive block has two output ports: Data and Size.

The Data port outputs the UDP packet data as an N-by-1 vector with a data type specified by the Data type parameter. The Size output emits the current size of the data in the UDP buffer as uint16 value.

The data type of the block output, Size, is uint16.

The Size port outputs a stream of zeros while UDP Receive waits for new data to arrive. When new data arrives, Size changes to a non-zero value.

If you simulate a model that contains the UDP Receive block on your host computer, set Simulation > Normal, then Data outputs a zero for each step of the simulation when no UDP packets are available. As a free-running application with a shorter period than the real-time application running on the Android® device, many zeros can be produced from the output port Data. In other words, the free-running simulation outputs zeros while waiting for the slower real-time application on the Android device to send data.


If you are having trouble using UDP to communicate with a computer, investigate if antivirus or firewall software is blocking UDP traffic. If so, try to configure the software to allow UDP traffic for a specific IP port number.


Local IP port

The number of the IP port on the local device, which can range from 1 – 65535. This value defaults to 25000. The “local device” is the board running the model.

Data type

Set the data type of the vector elements in the Message output. Match the data type with the data input used to create the UDP packets. This option defaults to uint8.

Data size (N)

Set the number of data elements in each UDP packet. Match the data size used to create the UDP packets. This value defaults to 255 elements.

Sample time

Specify how often this block reads the port buffer. Enter a value greater than zero. This value defaults to a sample time of 0.01 seconds.

Smaller values require the processor to complete the same number of instructions in less time, which can cause task overruns.

Extended Capabilities

C/C++ Code Generation
Generate C and C++ code using Simulink® Coder™.

Version History

Introduced in R2014a