This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

Socket Sendto() real-time udp stream



Hello again.

I'm trying to make my board (TMDXEVM6670L) to send packets to my PC, using following code:

for(;;)
	    {
	        tmp = sizeof( sin1 );

	        i = (int)recvnc( s, (void **)&pBuf, 0, &hBuffer );
	        printf(pBuf);
	        printf("\n");

	        poutbuf = outbuf;

	        if( i >= 0 )
	        {
	        	for (j = 1; j < 100; j++)
	        	{
	        		outval = j;
					ltoa(outval, poutbuf);//
	        		if (j < 10)
	        		{
	        			sendto(s, poutbuf, 1, 0,(PSA)&sin1, sizeof(sin1) );
	        			printf(poutbuf, "\n");
	        			platform_delay(40000); // 0.04 sec
	        		}
	        	 	if (j >= 10 && j <100)
	        		{
	        			sendto(s, poutbuf, 2, 0,(PSA)&sin1, sizeof(sin1) );
	        			printf(poutbuf, "\n");
	        			platform_delay(40000);
	        		}
	        		if (j >= 100 && j < 1000)
	        		{
	        			sendto(s, poutbuf, 3, 0,(PSA)&sin1, sizeof(sin1) );
	        			printf(poutbuf, "\n");
	        			platform_delay(40000);
	        		}
	        		if (j >= 1000 && j < 10000)
	        		{
	        			sendto(s, poutbuf, 4, 0,(PSA)&sin1, sizeof(sin1) );
						printf(poutbuf, "\n");
						platform_delay(40000);
	        		}
	        	}
	            sendto(s, 0, 0, 0,(PSA)&sin1, sizeof(sin1) );
	            recvncfree( hBuffer );
	        }
	        else
	            break;
	    }


The problem is, that operations do not work inside the loop, until the loop itself does not end. I need to send a large amount of packets like that, and i don't know why this is happening. Could you please help me to understand, how to rework this code properly?

  • Dear Taras,


    The problem is, that operations do not work inside the loop, until the loop itself does not end. I need to send a large amount of packets like that, and i don't know why this is happening. Could you please help me to understand, how to rework this code properly?

    I hope this loop will not end.
    Where you are decreasing the value of "i" and also for loop is in infinite loop.
    Can you please try the following code.

    for(;;)
    {
    tmp = sizeof( sin1 );
    
    i = (int)recvnc( s, (void **)&pBuf, 0, &hBuffer );
    printf(pBuf);
    printf("\n");
    
    poutbuf = outbuf;
    
    if( i >= 0 )
    {
    
    //Titus : Use it here or last line
    // i--;
    
    for (j = 1; j < 100; j++)
    {
    outval = j;
    ltoa(outval, poutbuf);//
    if (j < 10)
    {
    sendto(s, poutbuf, 1, 0,(PSA)&sin1, sizeof(sin1) );
    printf(poutbuf, "\n");
    platform_delay(40000); // 0.04 sec
    }
    if (j >= 10 && j <100)
    {
    sendto(s, poutbuf, 2, 0,(PSA)&sin1, sizeof(sin1) );
    printf(poutbuf, "\n");
    platform_delay(40000);
    }
    if (j >= 100 && j < 1000)
    {
    sendto(s, poutbuf, 3, 0,(PSA)&sin1, sizeof(sin1) );
    printf(poutbuf, "\n");
    platform_delay(40000);
    }
    if (j >= 1000 && j < 10000)
    {
    sendto(s, poutbuf, 4, 0,(PSA)&sin1, sizeof(sin1) );
    printf(poutbuf, "\n");
    platform_delay(40000);
    }
    }
    sendto(s, 0, 0, 0,(PSA)&sin1, sizeof(sin1) );
    recvncfree( hBuffer );
    //Titus
    i--;
    
    }
    else
    break;
    }

  • Ok, that i can understand. But why the "Sendto" functions are not responding? When i'm using them once, they are executing like i need, but they are not working inside loop. Why is this happening?
  • Firstly, try to send around 100 packets then increase it and test.

    Try this code.

    for(;;)
    {
    tmp = sizeof( sin1 );
    
    i = (int)recvnc( s, (void **)&pBuf, 0, &hBuffer );
    printf(pBuf);
    printf("\n");
    
    poutbuf = outbuf;
    
    if( i >= 0 )
    {
    
    //Titus : Use it here or last line
    i--;
    
    for (j = 1; j < 100; j++)
    {
    outval = j;
    ltoa(outval, poutbuf);//
    if (j < 10)
    {
    sendto(s, poutbuf, 1, 0,(PSA)&sin1, sizeof(sin1) );
    printf(poutbuf, "\n");
    platform_delay(40000); // 0.04 sec
    }
    
    }
    
    }
    
    else
    break;
    
    break;
    
    }

  • While step-by-step debug, sendto "slips" without performing and returns nor result neither error...
  • Okay, let me try it on my machine and update you.