if((bytes = recv(i, buf, sizeof(buf), 0)) <= 0)
{
if(bytes == 0)
{
std::cout<<"Client "<<inet_ntoa(Raddr.sin_addr)<<" closed on socket "<<i<<std::endl;
}else{
perror("recv");
}
closesocket(i);
FD_CLR(i, &master);
}else{
std::cout << buf << std::endl;
}
Disconnecting problems
I have a small problem with clients disconnecting from the server. Whenever the client leaves the server, the last buffer recieved from the client keeps looping(being printed to the screen) even though the client shouldn't be receiving anymore data. Anything obvious?
Hello?
Hmm, that's odd, looks like it should work. Stick a reference to bytes in your output line and see what it's getting set to when the client has left. If you've declared bytes as an unsigned type, of course, it'll never be < 0.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement