Hello
My program receives data from UDP (a packet of 414 byte data at a time, 400 times/sec)
and writes the received data (414 bytes) into a text file using fprintf()
and writes part of the data into image files using fprintf().
In a threaded function, the UDP communication and file write look like:
while(1)
{
int recvMsgSize = udpServer.ReceiveFrom(buffer, UDP_DATA_MAX, senderIP, senderPort);
if (recvMsgSize < 0)
{
AfxMessageBox("Receive failed");
}
buffer[recvMsgSize]='\0';
if (dlg->m_log_running)
{
dlg_setting->WriteSerial(buffer, recvMsgSize);
Decode_Image(buffer);
Decode_NavData(buffer);
}
stringToHexa_WiresharkForm(buffer, recvMsgSize, buffer_hex);
if (dlg->m_dataPrintType == 0) dlg->m_udpReceive.SetWindowTextA(buffer_hex);
else ;
if (dlg->m_log_running)
fprintf(ptr_logFile, "%s\n\n", buffer_hex);
}
For small data, it works well.
But repeatedly there is data loss after receiving about 8 MB of data.
Both of the image files (also using fprintf() ) and the text file have lost data.
While, the data captured by WireShark has no lost data..
The problem would be in UDP receive or fprintf().
Is it a memory-related problem? I'd like to understand how it occurred.
Thank you for any advises..!