필터 지우기
필터 지우기

Problems reading UDP packets

조회 수: 2 (최근 30일)
Stuart Layton
Stuart Layton 2011년 6월 28일
I have data coming in from another computer, in the form of UDP packets, that I'd like to plot in real time. To do this I have setup a UDP object and set a callback to be fired everytime a packet is received. This works pretty well for a few moments. function u = strippedDownReceiver(varargin)
args.host = '10.121.43.56';
args.rxPort = 5000;
args.txPort = 10000; % shouldn't matter as we aren't txing
args.udpObjBufferSize = 1024*8;
% -------------------------------------------
% Networking variables
% -------------------------------------------
u = [];
nPacket = 0;
% -------------------------------------------
% Start Everything up
% -------------------------------------------
initNetwork();
% -------------------------------------------
% Network and Buffer Related Function
% -------------------------------------------
function initNetwork()
u = udp(args.host, args.txPort, 'LocalPort', args.rxPort);
set(u,'BytesAvailableFcn', @udpPacketRxCallback);
fopen(u);
end
function udpPacketRxCallback(obj, event)
data = fread(obj);
%nPacket = nPacket + 1;
%disp(['Packets recieved:', num2str(nPacket)]);
disp('Packet read');
end
end
When I run the function the "Packet Read" message is displayed several times but eventually the message stop appearing. Using Wireshark I can verify that packets are in fact arriving on my machine. Also if I execute. fclose(u); fopen(u); the message appears again for a while but eventually stops again.
Am I doing something obviously wrong here? What is the right way to continue reading data off of the network without stuttering or stopping?

답변 (0개)

카테고리

Help CenterFile Exchange에서 Signal Integrity Kits for Industry Standards에 대해 자세히 알아보기

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by