Hello,
I have imported the stock "client" demo shipped with the MCSDK (2_00_05_17). I imported the file "newservers.c to edit the function, "dtask_udp_echo".
The problem is this: whenever I send the value "[go]" to the board, the first iteration of the loop does not appear to execute and only "[new_frame]" is delivered to the requesting computer. Upon repeating the request procedure, the full 100-length sequence is delivered as well as "[new_frame]" .
Why does this behavior only show itself on the first connection? What can be done to get rid of this problem?
Thanks you!
Below is my modified function in whole.
// dtask_udp_echo() - UDP Echo Server Daemon Function
// (SOCK_DGRAM, port 7)
//
// Returns "1" if socket 's' is still open, and "0" if its been closed
//
int ( SOCKET s, UINT32 unused )
{
struct sockaddr_in sin1;
struct timeval to;
int i,tmp,j,k;
char *pBuf;
char out[32];
HANDLE hBuffer;
(void)unused;
// Configure our socket timeout to be 3 seconds
to.tv_sec = 3;
to.tv_usec = 0;
setsockopt( s, SOL_SOCKET, SO_SNDTIMEO, &to, sizeof( to ) );
setsockopt( s, SOL_SOCKET, SO_RCVTIMEO, &to, sizeof( to ) );
for(;;)
{
tmp = sizeof( sin1 );
i = (int)recvncfrom( s, (void **)&pBuf, 0,(struct sockaddr *)&sin1, &tmp, &hBuffer );
// Spit any data back out
if( i >= 0 )
{
if(strncmp(pBuf,"[go]",4)==0)
{
for(k=0; k<100; k++)
{
//"total" is a global variable
sprintf(out,"%d %d %d\n",total, total,1);//rand()%1280,rand()%1280, 1);
total++;
j = sendto( s, out, strlen(out), 0,(struct sockaddr *)&sin1, sizeof(sin1) );
if(j<0)
printf("Problems sending...\n");
}
sprintf(out,"[new_frame]\n");
j = sendto( s, out, strlen(out), 0,(struct sockaddr *)&sin1, sizeof(sin1) );
printf("sending stuff...\n");
}
recvncfree( hBuffer );
}
else
break;
}
// Since the socket is still open, return "1"
// (we need to leave UDP sockets open)
return(1);