|
struct sockaddr_in local;
struct sockaddr_in from;
int localfd;
int ret=0;
int len;
unsigned char buffer[80];
struct fd_set readFds;
struct timeval timeval;
bzero((char *)&local,sizeof(local));
local.sin_family = AF_INET;
local.sin_addr.s_addr = htonl (INADDR_ANY);
local.sin_port = htons(gNetInfo.whoamiPort) ;
if((localfd=socket(AF_INET, SOCK_DGRAM, 0)) == ERROR)
{
logMsg("frame send Task socket() error:%s\n",(int)strerror(errno),0,0,0,0,0);
}
if(bind(localfd, (struct sockaddr *)&local, sizeof(struct sockaddr_in))==ERROR)
{
logMsg("frame send Task bind() error:%s\n",(int)strerror(errno),0,0,0,0,0);
}
timeval.tv_sec = 1;
timeval.tv_usec=0;
while(1)
{
FD_ZERO (&readFds);
FD_SET (localfd, &readFds);
ret = select(localfd+1,&readFds,0,0,&timeval);
if (ret == 0)
{
/* time out */
}
else if (FD_ISSET (localfd, &readFds))
{
len = recvfrom(localfd, buffer, 20, 0, (struct aockaddr *)&from, sizeof(struct sockaddr_in));
if(len>0)
{
/* data */
}
}
}
|
|