Send UDP packets to network
UDPSender object sends UDP packets to
To send UDP packets to the network:
Define and set up your UDP sender. See Construction.
step to send the packets according
to the properties of
dsp.UDPSender. The behavior
step is specific to each object in the toolbox.
Starting in R2016b, instead of using the
H = dsp.UDPSender returns
a UDP sender object,
H, that sends UDP packets to
a specified port.
H = dsp.UDPSender(' returns a UDP sender object,
each property set to the specified value.
Remote address to which to send data
Specify the remote (i.e., host) IP address to which the data
is sent. The default is
Remote port to which to send data
Specify the port at the remote IP address to which the data
is sent. The default is
Source of the
Specify how to determine the port on the host as |
Local port from which to send data
Specify the port from which to send data. This property applies
when you set the
|clone||Create UDP sender object with same property values|
|getNumInputs||Number of expected inputs to step method|
|getNumOutputs||Number of outputs of step method|
|isLocked||Locked status for input attributes and nontunable properties|
|release||Allow property value and input characteristics changes|
|step||Send a UDP packet to network|
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).
Send some UDP packets, and calculate the number of successfully transmitted bytes:
hudpr = dsp.UDPReceiver('LocalIPPort',31000); hudps = dsp.UDPSender('RemoteIPPort',31000); % To prevent the loss of packets, call the |setup| method % on the object before the first call to the |step| method. setup(hudpr); bytesSent = 0; bytesReceived = 0; dataLength = 128; for k = 1:20 dataSent = uint8(255*rand(1,dataLength)); bytesSent = bytesSent + dataLength; hudps(dataSent); dataReceived = hudpr(); bytesReceived = bytesReceived + length(dataReceived); end release(hudps); release(hudpr); fprintf('Bytes sent: %d\n', bytesSent); fprintf('Bytes received: %d\n', bytesReceived);
Bytes sent: 2560 Bytes received: 2560
This object implements the algorithm, inputs, and outputs described on the UDP Send block reference page. The object properties correspond to the block parameters.