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.

Supported Platforms

UDP is supported on these platforms:

  • Linux® 64-bit

  • macOS 64-bit

  • Microsoft® Windows® 64-bit

The UDP interface is supported on the same platforms as MATLAB®. For updates to the list of currently supported platforms, see

Configuration and Connection

  1. Make sure that you have the correct instrument driver installed for your device. Refer to your device documentation and the vendor website.

  2. Make sure that your device is supported in Instrument Control Toolbox™. See Is My Hardware Supported?.

  3. Make sure that Instrument Control Toolbox recognizes your device, by using the instrhwinfo function with the udp interface name. For example:

    ans = 
     HardwareInfo with properties:
             LocalHost: {6x1 cell}
        JarFileVersion: 'Version 3.7'
  4. Make sure you can create your UDP object. You create a UDP object with the udp function, which does not require the name of the remote host as an input argument. However, if you are using the object to communicate with a specific instrument, you should specify the remote host and the port number.

    Although UDP is a stateless connection, opening a UDP object with an invalid host name will generate an error. You can configure property values during object creation, such as the LocalPort property if you will use the object to read data from the instrument. For example, to create a UDP object associated with the remote host, remote port 4012, and local port 3533:

    u = udp('', 4012, 'LocalPort', 3533);

    You can verify the object by looking at the object properties, using the name you assigned to the object, u in this case.

    UDP Object : UDP-
    Communication Settings 
       RemotePort:         4012
       Terminator:         'LF'
    Communication State 
       Status:             closed
       RecordStatus:       off
    Read/Write State  
       TransferStatus:     idle
       BytesAvailable:     0
       ValuesReceived:     0
       ValuesSent:         0
  5. Make sure you can connect to the remote host, using the fopen function with the object name.


    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:

    !ping hostname
  6. 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 hostname/IP exists. Try !ping hostname.

    • Make sure the RemotePort and LocalPort are correct. RemotePort is the port that the other computer or application is listening to for UDP traffic. LocalPort is the port on the computer that MATLAB is listening to for UDP traffic.

    • Look at the setting of the DatagramTerminateMode property. The default setting of on makes UDP behave differently than other interfaces. Try both settings. You also may need to set other properties, such as buffer size. See Functions and Properties (ASCII) and Functions and Properties (Binary) for more information on properties and values.

    • UDP is not a reliable protocol and packets can be dropped. You may need to try sending or receiving multiple times.

    See Read and Write ASCII Data over UDP and Read and Write Binary Data over UDP for examples of communication over UDP and information on using properties.