YOUSEFUL / DELPHI / COMPONENTS
TAtlasMqttTransportEvent
The type of TAtlasMqttClient.OnCreateTransport: supply the byte pipe for the next connection attempt.
Description
TAtlasMqttTransportEvent = procedure(Sender: TObject; var Transport: TAtlasMqttTransport) of object;Transport is nil on entry. Set it to a new, unconnected descendant of TAtlasMqttTransport, or leave it nil to get a TAtlasTcpTransport. The client takes ownership, connects it, and frees it when the connection ends. It runs on the client's own thread before every attempt. Add Atlas.MqttTransport to uses.
This type has no members of its own beyond those listed in its description.
Examples
Simulate a slow link
A transport that delays every send, to see how an application copes. Everything else is plain TCP.
uses
System.SysUtils, System.Classes, Atlas.MqttTransport, Atlas.MqttClient;
type
TSlowTransport = class(TAtlasTcpTransport)
public
procedure Send(const Data: TBytes); override;
end;
TSlowLink = class
procedure CreateTransport(Sender: TObject; var Transport: TAtlasMqttTransport);
end;
procedure TSlowTransport.Send(const Data: TBytes);
begin
Sleep(50);
inherited;
end;
procedure TSlowLink.CreateTransport(Sender: TObject; var Transport: TAtlasMqttTransport);
begin
Transport := TSlowTransport.Create; // the client connects it, uses it and frees it
end;Related
TAtlasMqttClient · TAtlasMqttTransport · TAtlasTcpTransport