Exemplo n.º 1
0
 protected void HeartAsync()
 {
     ws.Send(SerializeHelper.Serialize(new Message {
         Accepter = this.UID,
         Protocal = (byte)MessageProtocalEnum.Login,
         Sender   = this.UID
     }));
     Task.Factory.StartNew(() =>
     {
         while (isConnecting)
         {
             if (ActiveTime.AddSeconds(5) <= DateTime.Now)
             {
                 if (ws.ReadyState == WebSocketState.Open)
                 {
                     ws.Send(SerializeHelper.Serialize(new Message
                     {
                         Sender   = this.UID,
                         Protocal = (byte)MessageProtocalEnum.Heart,
                         Accepter = this.UID
                     }));
                 }
                 else
                 {
                     //ReConnect();
                 }
             }
             Thread.Sleep(100);
         }
     });
 }
Exemplo n.º 2
0
 public void CheckConnect(object sender, System.Timers.ElapsedEventArgs e)
 {
     if (ActiveTime.AddSeconds(20) <= DateTime.Now)
     {
         ReConnect();
     }
 }
Exemplo n.º 3
0
 protected void HeartAsync()
 {
     Task.Factory.StartNew(() =>
     {
         while (_client.IsConnected)
         {
             try
             {
                 if (ActiveTime.AddSeconds(30) <= DateTime.Now)
                 {
                     this.SendMsgAsync(new Message
                     {
                         Protocal = (byte)MessageProtocalEnum.Heart,
                         Sender   = _client.UID
                     });
                 }
                 Thread.Sleep(1000);
             }
             catch (Exception ex)
             {
                 if (ex is SocketException)
                 {
                     ReConnectAsync();
                 }
             }
         }
     });
 }