If my client's connection is broken on the other end( kill -9 server)
. It takes several minutes for the client to determine that something is wrong. Socket.Connected
returns true even though connection is actually broken.
What is the fastest way to determine that the connection doesn't exist, once the other end breaks the link?
Client code:
try{
Socket socket= new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
/*Assume there is a connection on the other end*/
while (socket.Connected)
{
/*Do some processing*/
}
}catch (SocketException se){
Console.WriteLine(ex.Message);
} catch (Exception ex){
Console.WriteLine(ex.Message);
}
finally
{
Console.WriteLine("something bad happen");
}