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.

6678 UDP 接收数据问题,PC通过网络调试助手下发120字节数据,第一次能正常接收,第二次就一个也收不到了,UDP代码如下




/* 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 dtask_udp_echo( SOCKET s, UINT32 unused )
{
struct sockaddr_in sin1;
struct timeval to;
int i,tmp;
char *pBuf;
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 )
{
sendto( s, pBuf, i, 0,(struct sockaddr *)&sin1, sizeof(sin1) );
recvncfree( hBuffer );
}
else
break;
}

/* Since the socket is still open, return "1" */
/* (we need to leave UDP sockets open) */
return(1);
}