My intended-to-be-enterprise-class async TCP server will be serving 20,000+ connections at any given moment in time. I've written some code below to detect ungraceful client disconnects, but I'm not certain it will work. Is there a better way to do this?
public void PollUsers()
{
while (true)
{
Thread.Sleep(2000);
lock(users_lock)
{
foreach(Socket user_socket in users)
{
if (!IsConnected(user_socket))
Console.WriteLine("user disconnected");
}
}
}
}
public bool IsConnected(Socket socket)
{
try
{
return !(socket.Poll(1, SelectMode.SelectRead) && socket.Available == 0);
}
catch (SocketException) { return false; }
}