Advertisement
parabola949

Untitled

Aug 11th, 2014
229
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 1.63 KB | None | 0 0
  1. private void PingListener()
  2.         {
  3.             Thread.Sleep(TimeSpan.FromMinutes(1));
  4.             while (true)
  5.             {
  6.                 for (int i = _clients.Count; i >= 0; i++)
  7.                 {
  8.                     Version v = new Version(0,0,0,0);
  9.                     if (Version.TryParse(_clients[i].Version, out v))
  10.                     {
  11.                         if (v < new Version(2, 0, 5, 1))
  12.                         {
  13.                             //Client version does not support PING command!
  14.                             continue;
  15.                         }
  16.                     }
  17.                     else
  18.                     {
  19.                         //don't have the client version at all!
  20.                         continue;
  21.                     }
  22.  
  23.                     //fire off a message to the client, see what happens
  24.                     try
  25.                     {
  26.  
  27.                         byte[] buffer = _encoder.GetBytes("PING");
  28.                         var stream = _clients[i].TClient.GetStream();
  29.                         stream.Write(buffer, 0, buffer.Length);
  30.                         stream.Flush();
  31.                     }
  32.                     catch (Exception e)
  33.                     {
  34.                         //this client doesn't appear to be connected anymore.  We should get rid of it
  35.                         Logging.Write(e.Message);
  36.                         Logging.Event(e.Message, EventLogEntryType.Error);
  37.                         RemoveClient(_clients[i]);
  38.                        
  39.                     }
  40.                 }
  41.  
  42.                 Thread.Sleep(TimeSpan.FromMinutes(5));
  43.             }
  44.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement