Need help with detecting socket disconnection

Started by
1 comment, last by dave 18 years, 1 month ago
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.....
Advertisement
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.
You should be pinging each client ver regularly, when you don't get then reply you know something is up.

Dave

This topic is closed to new replies.

Advertisement