Click here to Skip to main content
15,891,597 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hallo evryone i am new in network programming.
Can anyone please help me to find a solution for this problem.
I would like to get continuous data packets form the server side, but i am always stuck with assert functions in the program.
So at a time i receive only one data packet,
I have done this with multithreading process.
I am not able to distinguish the error


Cheers!

What I have tried:

iLen = m_clientSocket.Receive(pBuf, 1024); //Receieve Data packet
	if (iLen == SOCKET_ERROR)
	{
		AfxMessageBox(L"Could not Recieve");
		return;
			}
			else
			{
				
				/*if (iLen == sizeof(struct udp_tackpacket_t))
				{
					struct udp_tackpacket_t* pstrFrame;
					pstrFrame = (struct udp_tackpacket_t*)pBuf;

					m_sharedData.szCounter.Format(_T("%d"), pstrFrame->header.counter);

				}*/

				pBuf[iLen] = NULL;
				strData = pBuf;
		m_data.Insert(m_data.GetLength(), strData);   //display in server
		UpdateData(FALSE);
		//int strdatalength = iLen;;
		//m_clientSocket.Send(strData, iLen);
		//UpdateData(FALSE)
Posted
Updated 3-Jul-19 3:56am
v2
Comments
Richard MacCutchan 3-Jul-19 5:34am    
You cannot guarantee receipt of UDP messages as they are like broadcasts. They are sent by the server but no checks are made to ensure either successful delivery or sending in the correct order.

If you Google for "socket sample" you will find lots of examples of how to do it correctly.
Member 14499788 3-Jul-19 7:00am    
Yeah , thanks for the suggestion!
I tried doing it many ways form internet.The main problem is I am not able to receive a continuosus udp packet. The programm stops after reciving one data packet
Richard MacCutchan 3-Jul-19 7:57am    
As each message is received you add the data to your current receive buffer and examine it to see where a server message starts and ends. The only problem is that UDP packets are not guaranteed, and may even arrive in the wrong order, so it becomes quite difficult to manage.
Member 14499788 3-Jul-19 8:02am    
Thanks!!
CPallini 3-Jul-19 8:44am    
Why it stops? What assertion fails? Please give more details.

1 solution

Have a look at this code samples: MFC Sockets[^].
Have also a look at this CodePrject article: Sending & Receiving UDP Datagrams with MFC's CAsyncSocket C++ Class[^].
 
Share this answer
 
Comments
Member 14499788 5-Jul-19 2:09am    
Hai CPallini
Thankyou for the suggestion.
my program works perfectly:):)
CPallini 5-Jul-19 2:45am    
You are welcome.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900