0

I'm interested to know how can I detect (at the server side ) that a socket connection failed when the client computer has the network cable plugged out or is hard reseted. This would be useful for a client server project in c#.

Currently I'm able to detect socket exceptions only when client closes the application and implicitly the socket.

Googling a bit I found abou the FD_CLOSE IEvent of WSAAsyncSelect . Would this work for the cases that I've described above ?

Stecya
  • 22,896
  • 10
  • 72
  • 102
klaus johan
  • 4,370
  • 10
  • 39
  • 56

1 Answers1

0

Take a look at this answer: Instantly detect client disconnection from server socket

UPDATE

Ok, i figured out what you are talking about. There is no way you can find out on the server if client cable is unplugged or something happens to it's network. You will simply not get any response from that client any more. Only way i can see is provided in link at beginning of this answer.

There is WSAEventSelect native method inside of Ws2_32.dll (Winsock2), but it's only used to detect network unavailability reason on local machine (where app runs).

I took a look inside System.Net.NetworkInformation.NetworkChange class source code and there you can see that everything related to WSAEventSelect is about local machine (in your case server).

Community
  • 1
  • 1
HABJAN
  • 9,212
  • 3
  • 35
  • 59
  • The MSDN documentation specifies that Poll() cannot be used to detect if the network cable is unplugged or the computer is ungracefully closed. – klaus johan Mar 31 '11 at 16:26