Socket failure detection
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 开发者_如何学JAVAcloses 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 ?
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).
精彩评论