Sign in to follow this  
cherryhouse

Disconnecting problems

Recommended Posts

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;
                    }

Share this post


Link to post
Share on other sites
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.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this