Troubleshooting UDP Interface
User Datagram Protocol (UDP or UDP/IP) is a transport protocol layered on top of the Internet Protocol (IP). UDP is a connectionless protocol. An application using UDP prepares a packet and sends it to the receiver's address without first checking to see if the receiver is ready to receive a packet. If the receiving end is not ready to receive a packet, the packet is lost.
If you are having trouble connecting to or communicating with your UDP socket, follow these troubleshooting tips.
UDP is supported on these platforms:
The UDP interface is supported on the same platforms as MATLAB®. For updates to the list of currently supported platforms, see System Requirements.
configureMulticast function is only supported on
Windows and not supported Linux or macOS.
Configuration and Connection
Make sure you can create your UDP object with the
Although UDP is a stateless connection, creating a UDP object with an invalid local host or local port generates an error. Specifying a local port that is in use elsewhere or a port with port sharing disabled also generates an error. You can configure property values during object creation, such as the
LocalPortproperty if you will use the object to read data. For example, create a
udpportobject associated with local port
u = udpport("LocalPort",3533)
u = UDPPort with properties: IPAddressVersion: "IPV4" LocalHost: "0.0.0.0" LocalPort: 3533 NumBytesAvailable: 0 Show all properties, functions
If the computer or host does not exist, you will get a warning. You can try to ping the computer to see if it is responding.
When you have connected, you can communicate with your device. If sending and receiving does not work, you can check the following:
Make sure the destination address and destination port parameters for sending data with
writelineare valid or exist. Try
Make sure the destination port and
LocalPortare correct. The destination port is the port on the other computer to which data is sent.
LocalPortis the port on the local computer that the
udpportobject is bound to.
UDP is not a reliable protocol and packets can be dropped. You may need to try sending or receiving multiple times.
See Write and Read ASCII Data Over UDP and Write and Read Binary Data Over UDP for examples of communication over UDP and information on using properties.