MQTT Publish Message and Wait Response

From sgcWebSockets 4.4.4 the MQTT client has a new method called PublishAndWait. Till now, when a client publishes a message using QoS levels 1 or 2, the only way to know if the message was processed by server was using the asynchronous events OnMQTTAcknowledgment or OnMQTTPubComp, this means that client must implement his own wait method to check if the message sent was acknowledged by server.

Now there is a specific method, PublishAndWait that does exactly that, it publishes the message and waits till server sends an acknowledgment to client, if client doesn't receives after a timeout, the function will return false.

The use of PublishAndWait is the same that normal Publish method, now you have a new parameter called Timeout, where method will return with value false if after certain period of time, there is no response from server. By default this value is 10 seconds.

if mqtt.PublishAndWait('topic', 'text') then
  ShowMessage('Message processed')
  ShowMessage('Message error'); 
Stay Informed

When you subscribe to the blog, we will send you an e-mail when there are new updates on the site so you wouldn't miss them.

Telegram Client and Proxies
Google Calendar Client API V3

Related Posts