Exemplo n.º 1
0
 /// <summary>
 ///     Initializes a new instance of the <see cref="PublishingManager" /> class.
 /// </summary>
 /// <param name="connectionHandler">The connection handler.</param>
 public PublishingManager(IMqttConnectionHandler         connectionHandler) {
     this.connectionHandler = connectionHandler;
     connectionHandler.RegisterForMessage(MqttMessageType.PublishAck, HandlePublishAcknowledgement);
     connectionHandler.RegisterForMessage(MqttMessageType.Publish, HandlePublish);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishComplete, HandlePublishComplete);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishRelease, HandlePublishRelease);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishReceived, HandlePublishReceived);
 }
Exemplo n.º 2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="PublishingManager"/> class.
 /// </summary>
 /// <param name="connectionHandler">The connection handler.</param>
 /// <param name="publishMessageCallback">The function that should be called when a publish message is received.</param>
 public PublishingManager(IMqttConnectionHandler connectionHandler, Func <MqttPublishMessage, bool> publishMessageCallback)
 {
     this.connectionHandler      = connectionHandler;
     this.publishMessageCallback = publishMessageCallback;
     connectionHandler.RegisterForMessage(MqttMessageType.PublishAck, HandlePublishAcknowledgement);
     connectionHandler.RegisterForMessage(MqttMessageType.Publish, HandlePublish);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishComplete, HandlePublishComplete);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishRelease, HandlePublishRelease);
     connectionHandler.RegisterForMessage(MqttMessageType.PublishReceived, HandlePublishReceived);
 }
Exemplo n.º 3
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);
        }
Exemplo n.º 4
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);
        }