This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English verison of the page.

Note: This page has been translated by MathWorks. Please click here
To view all translated materals including this page, select Japan from the country navigator on the bottom of this page.


System object: dsp.UDPReceiver
Package: dsp

Receive UDP packet


P = step (udpr)



Starting in R2016b, instead of using the step method to perform the operation defined by the System object™, you can call the object with arguments, as if it were a function. For example, y = step(obj) and y = obj() perform equivalent operations.

P = step (udpr) receives one UDP packet, P, from the network. The input argument, udpr, is a dsp.UDPReceiver object.


obj specifies the System object on which to run this step method.

The object performs an initialization the first time the step method is executed. This initialization locks nontunable properties (MATLAB) and input specifications, such as dimensions, complexity, and data type of the input data. If you change a nontunable property or an input specification, the System object issues an error. To change nontunable properties or inputs, you must first call the release method to unlock the object.

The first time you call the step method on a UDPReceiver object, the object also allocates resources and begins listening for data. As a result, the first step call may not receive data. To prevent the loss of packets, call the setup method on the object before the first call to the step method.


expand all

Note: This example runs only in R2016b or later. If you are using an earlier release, replace each call to the function with the equivalent step syntax. For dsp.UDPReceiver System object™, myObject() becomes step(myObject). For all other objects, myObject(x) becomes step(myObject,x).

This example shows how to send and receive one UDP packet. Set up the objects to send and receive UDP packets.

udps = dsp.UDPSender('RemoteIPPort',31000);
udpr = dsp.UDPReceiver('LocalIPPort',31000);

Create some data to send and receive.

 dataSent = uint8(255*rand(1,128));
 bytessent = length(dataSent);

Send and receive the data. Verify that the number of bytes is equal.

datain = udpr();
bytesreceived = length(datain);
ans =



Was this topic helpful?