TsgcWSPClient_MQTTMethods › Disconnect

Disconnect Method

Sends an MQTT DISCONNECT packet to end the session cleanly.

Overloads

Overload 1

Syntax

procedure Disconnect;

Remarks

Performs a standard MQTT disconnect using reason code 0 (Normal Disconnection) and no extra properties. Use this overload when the application simply wants to log off and suppress delivery of the Last Will message. The underlying WebSocket transport is not closed here; call the parent client's Disconnect to tear down the socket.

Example

MQTT.Disconnect;

Overload 2

Syntax

procedure Disconnect(aReasonCode: Integer; aDisconnectProperties: TsgcWSMQTTDisconnect_Properties = nil);

Parameters

NameTypeDescription
aReasonCodeIntegerMQTT 5.0 reason code reported to the broker (for example 0 = Normal, 4 = Disconnect with Will Message, 129 = Malformed Packet, 139 = Server Shutting Down).
aDisconnectPropertiesTsgcWSMQTTDisconnect_PropertiesOptional MQTT 5.0 properties such as Session Expiry Interval, Reason String, Server Reference or User Properties. Pass nil when no properties are required.

Remarks

MQTT 5.0 overload that lets the client signal why it is leaving. Setting aReasonCode to 4 asks the broker to publish the configured Last Will Testament, while any non-zero code causes the broker to log the abnormal close. Ignored when the session was negotiated as MQTT 3.1.1.

Example

oProps := TsgcWSMQTTDisconnect_Properties.Create;
try
  oProps.ReasonString := 'client shutting down';
  MQTT.Disconnect(0, oProps);
finally
  oProps.Free;
end;

Back to Methods