BVB Source Codes

SuperSocket v1.6.6 Show PushServer.cs Source code

Return Download SuperSocket v1.6.6: download PushServer.cs Source code - Download SuperSocket v1.6.6 Source code - Type:.cs
  1. 锘縰sing System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading;
  6. using SuperSocket.SocketBase;
  7. using SuperSocket.SocketBase.Config;
  8.  
  9. namespace SuperSocket.QuickStart.ServerPush
  10. {
  11.     public class PushServer : AppServer
  12.     {
  13.         private Timer m_PushTimer;
  14.  
  15.         private int m_Interval; //1 minute
  16.  
  17.         protected override bool Setup(IRootConfig rootConfig, IServerConfig config)
  18.         {
  19.             RegisterConfigHandler(config, "pushInterval", (value) =>
  20.                 {
  21.                     var interval = 0;
  22.                     int.TryParse(value, out interval);
  23.  
  24.                     if (interval <= 0)
  25.                         interval = 60;// 60 seconds by default
  26.  
  27.                     m_Interval = interval * 1000;
  28.                     return true;
  29.                 });
  30.  
  31.             return true;
  32.         }
  33.  
  34.         protected override void OnStarted()
  35.         {
  36.             m_PushTimer = new Timer(OnPushTimerCallback);
  37.             m_PushTimer.Change(m_Interval, m_Interval);
  38.             base.OnStarted();
  39.         }
  40.  
  41.         private void OnPushTimerCallback(object state)
  42.         {
  43.             try
  44.             {
  45.                 m_PushTimer.Change(Timeout.Infinite, Timeout.Infinite);
  46.                 PushToAllClients();
  47.             }
  48.             catch (Exception e)
  49.             {
  50.                 Logger.Error(e);
  51.             }
  52.             finally
  53.             {
  54.                 m_PushTimer.Change(m_Interval, m_Interval);
  55.             }
  56.         }
  57.  
  58.         private void PushToAllClients()
  59.         {
  60.             var now = DateTime.Now.ToString();
  61.  
  62.             foreach (var session in this.GetAllSessions())
  63.             {
  64.                 session.Send(now);
  65.             }
  66.         }
  67.  
  68.         protected override void OnStopped()
  69.         {
  70.             if (m_PushTimer != null)
  71.             {
  72.                 m_PushTimer.Change(Timeout.Infinite, Timeout.Infinite);
  73.                 m_PushTimer.Dispose();
  74.                 m_PushTimer = null;
  75.             }
  76.  
  77.             base.OnStopped();
  78.         }
  79.     }
  80. }
  81.  
downloadPushServer.cs Source code - Download SuperSocket v1.6.6 Source code
Related Source Codes/Software:
Students' basic information input program v2.0 - 1, the program is based on. net4.0 framework and d... 2016-08-19
Student information input system v2.0 - 1, the program is based on. net4.0 framework and d... 2016-08-19
Baidu handwriting input source v1.0 - Baidu handwriting input method source code, no nee... 2016-08-19
Rui bao tong v1.0 JAVA version of B2B e-commerce system - Rainbow B2B system developed using the popular JAV... 2016-08-19
HTML + javascript lottery system v2.1.1 HTA - Technology QQ:838341952 HTML+JS lottery system sta... 2016-08-19
Cloud on the CMS (SyCms) v1.95 - Add menus and blocks the system style functionalit... 2016-08-19
1.0 housing, rental housing sale platform - Rent housing rent out platform is a very typical r... 2016-08-19
Deng Xi v2.4 website help system - Deng Xi website help system is a very useful help ... 2016-08-19
Address book v1.0 FaLiang three layer - This Demo is a three layer address book source cod... 2016-08-19
Ray speed v7.0 wage query system - To modify the software to conduct a comprehensive ... 2016-08-19
MTStatusBarOverlay - A custom iOS status bar overlay seen in Apps like ... 2017-05-12
blueprint - Reverse engineer server configuration ... 2017-05-12
PullToRefresh - A simple iPhone TableViewController for adding the... 2017-05-12
mrjob - Run MapReduce jobs on Hadoop or Amazon Web Service... 2017-05-11
wax - Wax is now being maintained by alibaba ... 2017-05-11
ledisdb - a high performance NoSQL powered by Go ... 2017-05-11
d3-cloud - Create word clouds in JavaScript. ... 2017-05-11
react-makes-you-sad - Here's a flowchart to make you happy again! 2017-05-11
flat-surface-shader - Flat Surface Shader for rendering lit triangles to... 2017-05-11
flat-surface-shader - Flat Surface Shader for rendering lit triangles to... 2017-05-11

 Back to top