Jump to content
  • Advertisement
Sign in to follow this  
kahwai

Need help with detecting socket disconnection

This topic is 4488 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

Hi, I'm developing a server using c++ blocking, multithreaded and multi-client socket(Winsock) programming. My problem is when the client got a connection disruption, the server won't automatically detects it and keep receiving data from the client. I'm curious why can't it auto detect since this is a blocking connection. Is it because of the multithreading? Anyway, I tried to detect the disconnected client by adding the client socket into a list array and then detect with a recv using a timer. I managed to detect the disconnected client by this way but when i try to close the socket, the program will crash. I think the reason for this is the socket is still receiving data in another thread. I don't want to close my listener socket just because of 1 disconnected client. Please help me.....

Share this post


Link to post
Share on other sites
Advertisement
Guest Anonymous Poster
if you send data to the client, you will receive an error if they are disconnected. Then you can simply close the connection. I would recommend moving to asyncronous windows sockets if targeting the windows platform. This way you receive windows messages for all you events.

Share this post


Link to post
Share on other sites
You should be pinging each client ver regularly, when you don't get then reply you know something is up.

Dave

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!