I am new to socket programming and I am trying to write code for a client that sends and receives messages on both TCP and UDP. I am using select() system call for it. My problem is, select() works fine for TCP but it doesn't go inside the if loop for UDP and hence no messages are being received on UDP. The sendto() seems to be working fine as it returns a positive integer value.
I am not able to figure out the reason. Here is some of my code. Any help is appreciated.
fd_set master; // master file descriptor list
FD_SET(child_fd,&master); //child_fd is socket descriptor for TCP
FD_SET(sockudpfd,&master); //sockudpfd is socket descriptor for UDP
struct timeval t;
if(select(255, &master, (fd_set *)0, (fd_set *)0,(struct timeval *)0) < 0)
perror("select error \n");
// some computation goes here...where "sendmsg" is calculated
udp_send=sendto(sockudpfd, sendmsg, strlen(sendmsg), 0, (struct sockaddr *)&cliaddr, sizeof(cliaddr));
else if(FD_ISSET(sockudpfd, &master)) // this loop doesnt work.}
int m=recvfrom(sockudpfd, udpmesg, 500, 0, (struct sockaddr *) &cliaddr, &cli_len);