Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void PingListener()
- {
- Thread.Sleep(TimeSpan.FromMinutes(1));
- while (true)
- {
- for (int i = _clients.Count; i >= 0; i++)
- {
- Version v = new Version(0,0,0,0);
- if (Version.TryParse(_clients[i].Version, out v))
- {
- if (v < new Version(2, 0, 5, 1))
- {
- //Client version does not support PING command!
- continue;
- }
- }
- else
- {
- //don't have the client version at all!
- continue;
- }
- //fire off a message to the client, see what happens
- try
- {
- byte[] buffer = _encoder.GetBytes("PING");
- var stream = _clients[i].TClient.GetStream();
- stream.Write(buffer, 0, buffer.Length);
- stream.Flush();
- }
- catch (Exception e)
- {
- //this client doesn't appear to be connected anymore. We should get rid of it
- Logging.Write(e.Message);
- Logging.Event(e.Message, EventLogEntryType.Error);
- RemoveClient(_clients[i]);
- }
- }
- Thread.Sleep(TimeSpan.FromMinutes(5));
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement