예제 #1
0
        /// <summary>
        ///     Initializes a new instance of the <see cref="MqttConnectionKeepAlive" /> class.
        /// </summary>
        /// <param name="connectionHandler">The connection to keep alive.</param>
        /// <param name="keepAliveSeconds">The keep alive duration in seconds.</param>
        public MqttConnectionKeepAlive(IMqttConnectionHandler connectionHandler, int keepAliveSeconds) {
            this.connectionHandler = connectionHandler;
            this.keepAlivePeriod = keepAliveSeconds*1000;

            // register for message handling of ping request and response messages.
            connectionHandler.RegisterForMessage(MqttMessageType.PingRequest, PingRequestReceived);
            connectionHandler.RegisterForMessage(MqttMessageType.PingResponse, PingResponseReceived);
            connectionHandler.RegisterForAllSentMessages(MessageSent);

            // Start the timer so we do a ping whenever required.
            pingTimer = new Timer(PingRequired, null, keepAlivePeriod, keepAlivePeriod);
        }
예제 #2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="MqttConnectionKeepAlive"/> class.
        /// </summary>
        /// <param name="connection">The connection to keep alive.</param>
        /// <param name="keepAliveSeconds">The keep alive duration in seconds.</param>
        public MqttConnectionKeepAlive(IMqttConnectionHandler connectionHandler, int keepAliveSeconds)
        {
            this.connectionHandler = connectionHandler;
            this.keepAlivePeriod   = keepAliveSeconds * 1000;

            // register for message handling of ping request and response messages.
            connectionHandler.RegisterForMessage(MqttMessageType.PingRequest, PingRequestReceived);
            connectionHandler.RegisterForMessage(MqttMessageType.PingResponse, PingResponseReceived);
            connectionHandler.RegisterForAllSentMessages(MessageSent);

            // Start the timer so we do a ping whenever required.
            pingTimer = new Timer(PingRequired, null, keepAlivePeriod, keepAlivePeriod);
        }