Example #1
0
        /// <summary>
        ///     Signal to the keepalive that a ping request has been received from the message broker.
        /// </summary>
        /// <remarks>
        ///     The effect of calling this method on the keepalive handler is the transmission of a ping response
        ///     message to the message broker on the current connection.
        /// </remarks>
        private bool PingRequestReceived(MqttMessage pingMsg)
        {
            Monitor.Enter(shutdownPadlock);
            try {
                if (!disposed)
                {
                    var pingRespMessage = new MqttPingResponseMessage();
                    connectionHandler.SendMessage(pingRespMessage);

                    pingTimer.Change(keepAlivePeriod, keepAlivePeriod);
                }
            } finally {
                Monitor.Exit(shutdownPadlock);
            }

            return(true);
        }
Example #2
0
        public void BasicDeserialization()
        {
            // standard byte array of a ping response message.
            var expected = new[]
            {
                (byte)0xD0,
                (byte)0x00,
            };

            MqttPingResponseMessage msg = new MqttPingResponseMessage();
            Console.WriteLine(msg);

            byte[] actual = MessageSerializationHelper.GetMessageBytes(msg);

            Assert.Equal<int>(expected.Length, actual.Length);
            Assert.Equal<byte>(expected[0], actual[0]); // first header byte
            Assert.Equal<byte>(expected[1], actual[1]); // message size byte
        }
Example #3
0
        /// <summary>
        /// Signal to the keepalive that a ping request has been received from the message broker.
        /// </summary>
        /// <remarks>
        /// The effect of calling this method on the keepalive handler is the transmission of a ping response
        /// message to the message broker on the current connection.
        /// </remarks>
        private bool PingRequestReceived(MqttMessage pingMsg)
        {
            Monitor.Enter(shutdownPadlock);
            try
            {
                if (!disposed)
                {
                    MqttPingResponseMessage pingRespMessage = new MqttPingResponseMessage();
                    connectionHandler.SendMessage(pingRespMessage);

                    pingTimer.Change(keepAlivePeriod, keepAlivePeriod);
                }
            }
            finally
            {
                Monitor.Exit(shutdownPadlock);
            }

            return true;
        }