I have to processes running on one machine. One of them is the server and the other one is the client. The client sends messages through a connectionless datagram socket like this:
for(int i = 0; i < 5000; i++)
{
char buf[100];
sprintf(buf, "%d\n", i);
if ((numbytes = sendto(sockfd, buf, strlen(buf), 0,
(struct sockaddr *)&their_addr, sizeof(struct sockaddr))) == -1) {
printf("%d", WSAGetLastError());
perror("sendto");
exit(1);
}
}
if ((numbytes = sendto(sockfd, "stop", 4, 0,
(struct sockaddr *)&their_addr, sizeof(struct sockaddr))) == -1) {
printf("%d", WSAGetLastError());
perror("sendto");
exit(1);
}
The server recieves the messages like this:
int count = 0;
while(1)
{
if ((numbytes=recvfrom(sockfd, buf, MAXBUFLEN-1 , 0,
(struct sockaddr *)&their_addr, &addr_len)) == -1) {
perror("recvfrom");
exit(1);
}
buf[numbytes] = '\0';
if(!strcmp(buf, "stop"))
break;
fprintf(log, buf);
count++;
}
fprintf(log, "Messages recieved: %d", count);
The server is launched first. The problem is that no errors are reported from sendto and recvfrom, but the server always gets only the first 1860 messages, and never breaks out from the loop as it does not recieve the 'stop' message from the client. I can run the client as many times as I want, and everytime the server is logging the first 1860 messages and keeps running. Any ideas why it might happen?