TsgcWSPClient_MQTT › Methods › Disconnect
Sends an MQTT DISCONNECT packet to end the session cleanly.
procedure Disconnect;
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.
MQTT.Disconnect;
procedure Disconnect(aReasonCode: Integer; aDisconnectProperties: TsgcWSMQTTDisconnect_Properties = nil);
| Name | Type | Description |
|---|---|---|
aReasonCode | Integer | MQTT 5.0 reason code reported to the broker (for example 0 = Normal, 4 = Disconnect with Will Message, 129 = Malformed Packet, 139 = Server Shutting Down). |
aDisconnectProperties | TsgcWSMQTTDisconnect_Properties | Optional MQTT 5.0 properties such as Session Expiry Interval, Reason String, Server Reference or User Properties. Pass nil when no properties are required. |
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.
oProps := TsgcWSMQTTDisconnect_Properties.Create;
try
oProps.ReasonString := 'client shutting down';
MQTT.Disconnect(0, oProps);
finally
oProps.Free;
end;