hello, i'm making a messaging app using udp to handle clients and tcp to handle admin
struct sockaddr_in si_minhaTCP,si_minhaUDP, si_outra;
int nready, maxfdp1;
int fdTcp;
int fdUdp;
fd_set rset;
if (argc != 4) {
printf("server {client port(udp)} {admin port(tcp)} {registry file path}\n");
exit(-1);
}
fdTcp = socket(AF_INET, SOCK_STREAM, 0);
bzero(&si_minhaTCP, sizeof(si_minhaTCP));
si_minhaTCP.sin_family = AF_INET;
si_minhaTCP.sin_addr.s_addr = htonl(INADDR_ANY);
si_minhaTCP.sin_port = htons((short) atoi(argv[2]));
bind(fdTcp, (struct sockaddr*)&si_minhaTCP, sizeof(si_minhaTCP));
listen(fdTcp, 10);
fdUdp = socket(AF_INET, SOCK_DGRAM, 0);
si_minhaUDP.sin_family = AF_INET;
si_minhaUDP.sin_addr.s_addr = htonl(INADDR_ANY);
si_minhaUDP.sin_port = htons((short) atoi(argv[1]));
bind(fdUdp, (struct sockaddr*)&si_minhaUDP, sizeof(si_minhaUDP));
FD_ZERO(&rset);
maxfdp1 = max(fdTcp, fdUdp) + 1;
for (;;)
{
FD_SET(fdTcp, &rset);
FD_SET(fdUdp, &rset);
nready = select(maxfdp1, &rset, NULL, NULL, NULL);
if (FD_ISSET(fdTcp, &rset))
{
}
if (FD_ISSET(fdUdp, &rset))
{
pid = fork();
if (pid == 0)
{
while(1)
{
if((recv_len = recvfrom(fdUdp, username, BUFLEN, 0, (struct sockaddr *) &si_outra, (socklen_t *)&slen)) == -1) {
erro("Erro recvfrom");
}
username[recv_len]='\0';
if((recv_len = recvfrom(fdUdp, password, BUFLEN, 0, (struct sockaddr *) &si_outra, (socklen_t *)&slen)) == -1)
{
erro("Erro no recvfrom");
}
password[recv_len]='\0';
printf("Username received: %s\n" , username);
printf("Password received: %s\n" , password);
char msg[]="CONFIRMED";
if(sendto(fdUdp, (const char *)msg, strlen(msg), 0, (struct sockaddr *) &si_outra, slen)==-1)
{
erro("Sendto");
}
char option[BUFLEN];
if((recv_len = recvfrom(fdUdp, option, BUFLEN, 0, (struct sockaddr *) &si_outra, (socklen_t *)&slen)) == -1)
{
perror("Error: ");
}
option[recv_len]='\0';
printf("option:%s\n",option);
}
}
}
}
After the first sendto i can no longer receive anything from client, i dont get any error in client and i can see in wireshark that the client sended, but i never receive anything in the server
What I have tried:
I've tested receiving before the sendto and it receives just fine.