Ejemplo n.º 1
0
        private void KeepaliveTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            if (keepaliveTimestamp <= DateTime.UtcNow)
            {
                CoapToken   token = CoapToken.Create();
                ushort      id    = CoapSender.NewId(token.TokenBytes);
                CoapRequest ping  = new CoapRequest
                {
                    MessageId   = id,
                    Token       = token.TokenBytes,
                    Code        = CodeType.EmptyMessage,
                    MessageType = CoapMessageType.Confirmable
                };

                OnKeepAlive?.Invoke(this, new CoapMessageEventArgs(ping));
            }
        }
Ejemplo n.º 2
0
        private void KeepaliveTimer_Elapsed(object sender, ElapsedEventArgs e)
        {
            //DateTime expiry = keepaliveExpiry.AddSeconds(Convert.ToDouble(_keepaliveSeconds * 1.5));

            //communicates to server keep alive expired
            //if (expiry < DateTime.Now)
            //{
            //    OnKeepAliveExpiry?.Invoke(this, null);
            //return;
            //}

            //signals client to send a ping to keep alive
            if (keepaliveExpiry < DateTime.Now)
            {
                OnKeepAlive?.Invoke(this, new MqttMessageEventArgs(new PingRequestMessage()));
            }
        }