TsgcWSPClient_MQTTイベント › OnMQTTDisconnect

OnMQTTDisconnect イベント

ブローカーが DISCONNECT を送信するかセッションが閉じられたときに発生します。ReasonCode と MQTT 5 DisconnectProperties を報告します。

構文

property OnMQTTDisconnect: TsgcWSMQTTDisconnectEvent;
// TsgcWSMQTTDisconnectEvent = procedure(Connection: TsgcWSConnection; ReasonCode: Integer; const ReasonName: String; DisconnectProperties: TsgcWSMQTTDISCONNECTProperties) of object

デフォルト値

解説

MQTT セッションが終了することを示します。MQTT 3.1.1 にはサーバー起動の DISCONNECT パケットがないため、その場合イベントはローカルで検出されたクローズを反映します。MQTT 5.0 では、ブローカーが接続を閉じる理由を説明するために送信できる DISCONNECT パケットが導入されています。パラメータ:

このイベントを使用して原因をログに記録し、UI の状態を更新し、ServerReference が設定されている場合は提案されたブローカーへの再接続を検討します。

使用例

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;

イベントに戻る