/* 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);
}
Shine:
请问第二次不能接收时程序卡跑到哪里了?用的是NDK里的helloworld udp例程吗?有没有做修改?板子是自己的还是EVM板?
Shine:
回复 user5312648:
感谢分享!