System object: dsp.UDPReceiver
Receive UDP packet
P = step (udpr)
Starting in R2016b, instead of using the
to perform the operation defined by the System
object™, you can
call the object with arguments, as if it were a function. For example,
= step(obj) and
y = obj() perform equivalent
P = step (udpr) receives
one UDP packet,
P, from the network. The input
udpr, is a
obj specifies the System
which to run this
The object performs an initialization the first time the
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
to unlock the object.
The first time you call the
step method on
UDPReceiver object, the object also allocates resources
and begins listening for data. As a result, the first
may not receive data. To prevent the loss of packets, call the
on the object before the first call to the
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.
udps(dataSent); datain = udpr(); bytesreceived = length(datain); isequal(length(bytessent),length(bytesreceived))
ans = logical 1