我用下面的代码,只能收到fds[0]的数据,为什么呀,第一次用select,大虾给指点一下吧!
int fds[2];/*生成两个socket*/
...
FD_ZERO (&readFds);
for (i=0; i<2; i++)
{
FD_SET (fds[i], &readFds);
width = (fds[i] > width) ? fds[i] : width;
}
width++;
FOREVER
{
if (select(width, &readFds,NULL,NULL,NULL) == ERROR)
{
printErr ("wdbUdpSockLib: select failed!\n");
return (0);
}
for (i=0; i<2; i++)
{
if (FD_ISSET (fds[i], &readFds))
{
if(recvfrom(fds[i],(char *)&clientRequest,sizeof(clientRequest),0,(struct sockaddr *)&clientAddr,&sockAddrSize) == ERROR)
{
perror("bind");
close(fds[i]);
return(ERROR);
}
sprintf(sRecv,"%s%d ",sRecv,clientRequest[0]);
printf("%s\n",sRecv);
}
}
}