TsgcWSPClient_MQTT › Events › OnMQTTDisconnect
Fires when the broker sends a DISCONNECT or the session is closed; reports ReasonCode and MQTT 5 DisconnectProperties.
property OnMQTTDisconnect: TsgcWSMQTTDisconnectEvent;
// TsgcWSMQTTDisconnectEvent = procedure(Connection: TsgcWSConnection; ReasonCode: Integer; const ReasonName: String; DisconnectProperties: TsgcWSMQTTDISCONNECTProperties) of object
—
Signals that the MQTT session is being terminated. MQTT 3.1.1 has no server-initiated DISCONNECT packet, so in that case the event reflects a locally detected close. MQTT 5.0 introduces a DISCONNECT packet that the broker can send to explain why the connection is being closed. Parameters:
Use this event to log the cause, update UI state and, if ServerReference is set, consider reconnecting to the suggested broker.
procedure TForm1.MQTTDisconnect(Connection: TsgcWSConnection;
ReasonCode: Integer; const ReasonName: String;
DisconnectProperties: TsgcWSMQTTDISCONNECTProperties);
begin
Memo1.Lines.Add(Format('Disconnect %d (%s)',
[ReasonCode, ReasonName]));
if DisconnectProperties.ServerReference <> '' then
Memo1.Lines.Add('Broker suggests: ' +
DisconnectProperties.ServerReference);
end;