Sign in to follow this  
kahwai

Need help with detecting socket disconnection

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

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