www.gusucode.com > dsp 案例源码程序 matlab代码 > dsp/ReceiveOneUDPPacketExample.m
%% Receive one UDP Packet %% % *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(TM), 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. hsend = dsp.UDPSender('RemoteIPPort',31000); hreceive = 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. hsend(dataSent); datain = hreceive(); bytesreceived = length(datain); isequal(length(bytessent),length(bytesreceived)) %% % release(hsend); release(hreceive);