UDP Receive

Receive UDP packets over the Ethernet link between development and target computers


Simulink® Real-Time™ Library for Legacy UDP


The UDP Receive receives a byte stream (represented as a vector of uint8 values) from the UDP board. Use the Byte Unpacking block to convert from the vector of uint8 values to the signal data type.

IP fragmentation is not supported in Simulink Real-Time UDP blocks. The packet payload is limited to 1472 bytes (1500 bytes UDP packet size − 28 bytes combined packet header size).

Block Outputs



Vector of uint8 containing data received


Number of new bytes received, and otherwise 0

The default block behavior is to keep the previous output when there is no new data.

Block Parameters

IP address to receive from

Enter a valid IP address as a dotted decimal string. For example, You can also use a MATLAB® expression that returns a valid IP address as a string.

Can be left with the default value of This accepts all UDP packets from any accessible computer. If set to a specific IP address, only packets arriving from that IP address are received.

IP port to receive from

Receiver port that the block accepts data from. The other end of the communication sends data to the port specified here. This value must match the Remote IP port to send to parameter of the UDP Send block

Output port width

Width of the acceptable packets, in bytes. You can obtain this number when designing the other side (send side) of the communication. If you select Allow variable length packets, this parameter defines the maximum length of the message.

If Allow variable length packets is cleared, the block receives only packets of Output port width length. It discards the other packets.

Allow variable length packets

Select this check box to enable the reception of variable length messages. The value of Output port width defines the maximum length of the message. If this check box is selected, the first output port sends the actual data. If the port size is less than the size of the actual data, the block sends up to the allowed length of data. It discards the extra data. The UDP Receive block does not return the number of discarded bytes. The behavior of the second output port depends on what environment the block is in:

  • If the block is in the Simulink Real-Time environment, the second output port sends the length of the original incoming message, m.

  • If the block is in the Simulink environment, the second output port sends the size of the first output port +1.

If this check box is cleared (default), the first output port contains the actual data, and the second output port contains:

  • 1, if the block receives the packet.

  • 0, if the block does not receive the packet.

Sample time

You can set this parameter to -1 for an inheritable sample time, but you should set this parameter to some specific (small) value to eliminate chances of dropped packets. This is especially true when you are using a small base sample time.

See Also


External Websites

Was this topic helpful?