Advertisement

Disconnecting problems

Started by March 14, 2006 04:12 PM
1 comment, last by cherryhouse 18 years, 11 months ago
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?
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;
                    }
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.
Advertisement
For some strange reason, I declared bytes as a socket... Problem solved.
Hello?

This topic is closed to new replies.

Advertisement