Jump to content
  • Advertisement
Sign in to follow this  
cherryhouse

Disconnecting problems

This topic is 4485 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

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
Advertisement
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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!