Client send data to socket every 10 sec. Like this:
rv Write: 1 1 rv Write: 1 2 rv Write: 1 3 rv Write: 1 4
Server stops receiving anything from this client after few minutes. Server log:
14:56:07 32 14:56:17 33 14:56:27 34 14:56:37 35 14:56:47 36 14:56:57 37
37 is last data from client. But the program continues send data to the server:
rv Write: 1 38 rv Write: 1 39 rv Write: 1 40 rv Write: 1 41 rv Write: 1 42 rv Write: 1
while(1){
fd_set set;
int rv;
struct timeval timeout;
int n;
FD_ZERO(&set);
FD_SET(sockfd, &set);
timeout.tv_sec = 10;
timeout.tv_usec = 0;
rv = select(sockfd + 1, NULL, &set, NULL, &timeout);
std::cout << "rv Write: " << rv << std::endl;
if(rv == -1){
printf("ERROE select\n");
}
else if(rv == 0){
printf("WRITE timeout\n");
}
else{
//char result[100];
std::string s = std::to_string(h);
char const *result = s.c_str();
n = write(sockfd,result,strlen(result));
if (n < 0){
printf("Write error\n");
}
else if (n == 0){
printf("Socket disconnected (write)\n");
}
else{
std::cout << h << '\n';
//break;
}
}
h++;
sleep(10);
}
Help to understand what is the problem?
Aucun commentaire:
Enregistrer un commentaire