Exemple #1
0
        private void Init()
        {
            thr = new System.Threading.Thread(new System.Threading.ThreadStart(() =>
            {
                while (true)
                {
                    try
                    {
                        DateTime now         = DateTime.Now;
                        var outOfTimeObjKeys = _connectingClientDic.Where(d =>
                        {
                            return((DateTime.Now - d.Value.LastHeartBeatTime).TotalSeconds > 10);
                        }).Select(d => d.Key).ToList();

                        foreach (var key in outOfTimeObjKeys)
                        {
                            OnlineStateObject removeObj = null;
                            _connectingClientDic.TryRemove(key, out removeObj);
                            OnClientDisConnectService(key);
                        }

                        System.Threading.Thread.Sleep(10000);
                    }
                    catch (Exception ex)
                    {
                        //throw;
                    }
                }
            }));
        }
Exemple #2
0
        protected virtual void HeartBeat(Object sender, string argJson)
        {
            var  playerIdStr = JSONSerilizer.GetJsonNode(argJson, "playerId");
            Guid playerId    = Guid.Empty;

            if (Guid.TryParse(playerIdStr, out playerId))
            {
                OnlineStateObject obj = new OnlineStateObject {
                    LastHeartBeatTime = DateTime.Now, OnlineWorkObject = sender
                };
                _connectingClientDic.AddOrUpdate(playerId, obj, (key, value) => obj);
            }
        }
Exemple #3
0
 protected virtual void SendToPlayer(Guid playerId, string msg)
 {
     try
     {
         OnlineStateObject stateObj = null;
         if (_connectingClientDic.TryGetValue(playerId, out stateObj))
         {
             if (stateObj.OnlineWorkObject != null)
             {
                 netWork.SendMsg(stateObj.OnlineWorkObject, msg);
             }
         }
     }
     catch (Exception)
     {
         throw;
     }
 }