views:

222

answers:

1

I've created a client server application with c++ CSocket. when I connect the client to the server and after that I close the client with normal X button or end task it with taskmanager , server CSocket receives the OnClose event. The problem is when I disable the internet connection on windows that the client is running on, server CSocket doesn't receive the OnClose nor OnReceive event!

Is anyone possibly know what's going on?

Update: I've just tested and saw that client didn't recieve the OnClose too! I disabled the internet connection on the windows that the client is running on!

+1  A: 

The client side is shutdown without being able to close the connection to the server via a FIN or RST. For the server to detect that the client is dead it must either have data to send (which would fail) or must send periodic TCP keepalive probes. TCP_KEEPALIVE can be set as a socket option.

David Joyner
Thanks, should i set keep alive on both server and client you think?
EBAGHAKI
Depends on what you're trying to protect against.If you enable server side keepalive that will prevent a connection from sitting dormant in case the client is shutdown as described above. Again, this is only necessary in the case where the server is never writing to the socket.Client side keepalive probbably makes less sense since presumably your client is writing to the socket and also if a client connection consumes resources it is usually no big deal.
David Joyner