here is code snippet for tcp and udp echoclient server using select.i had done with poll and got a good clarity but when coming to select it had described in the book ie in the below code snippet we should take (maxpl+2) i did不明白,首先为什么我们要使用 max(tcp_sfd,udp_sfd)?
fd_set fdvar;
FD_ZERO(&fdvar);
FD_SET(tcp_sfd,&fdvar);
FD_SET(udp_sfd,&fdvar);
int maxpl = max(tcp_sfd,udp_sfd);
cout << "Waiting for a client...\n";
if(select(maxpl+2 ,&fdvar,NULL,NULL,NULL)==-1)
{
perror("error in select");
}
if(FD_ISSET(udp_sfd,&fdvar))
{
// UDP
}
else
{
//TCP
}