Debugging Delphi Firemonkey Indy TCP Server

  

I have a Delphi Firemonkey application implementing a TCP server. The server is not opening the port as expected. I can see the form open but netstat reveals that the port is not opened. I am now attempting to debug this issue by trying to put log messages.

The trouble is I have never used Firemonkey before. I am not sure where I can expect to see the log messages.

I have declared a logging service.

LoggingService: IFMXLoggingService;

And then I initialize it

LoggingService := FMX.Platform.TPlatformServices.Current.GetPlatformService(IFMXLoggingService) as IFMXLoggingService;

And then I call this inside the function Tserver.Execute to make sure that it is executed.

if Assigned(LoggingService) then
LoggingService.Log(‘TserverExecute !’,[]);

I am not sure where to expect the output. I have checked various debug terminals, can’t seem to find the output string anywhere. It would be great if someone could point out what I am doing wrong?

unit Unit1;

interface

uses
System.SysUtils, System.Types, System.UITypes, System.Classes, System.Variants,
FMX.Types, FMX.Controls, FMX.Forms, FMX.Graphics, FMX.Dialogs, FMX.Platform,
IdCustomTCPServer, IdTCPServer, IdBaseComponent, IdComponent, IdUDPBase, IdContext,
IdSocketHandle, IdUDPServer, FMX.Controls.Presentation, FMX.StdCtrls;

type
TForm1 = class(TForm)
TCPServer: TIdTCPServer;
Label1: TLabel;
procedure FormCreate(Sender: TObject);
procedure FormShow(Sender: TObject);
procedure TserverExecute(AContext: TIdContext);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
LoggingService: IFMXLoggingService;

implementation

{$R *.fmx}

procedure TForm1.FormCreate(Sender: TObject);
var
Binding : TIdSocketHandle;
begin
LoggingService := FMX.Platform.TPlatformServices.Current.GetPlatformService(IFMXLoggingService) as IFMXLoggingService;
TCPServer.DefaultPort := 16000;
TCPServer.Bindings.Clear;
Binding := TCPServer.Bindings.Add;
Binding.IP := ‘0.0.0.0’;
Binding.Port := 16000;
end;

procedure TForm1.FormShow(Sender: TObject);
begin
TCPServer.Active := True;
end;

procedure TForm1.TserverExecute(AContext: TIdContext);
var
C : String;
begin
C := AContext.Connection.Socket.ReadLn();
if Assigned(LoggingService) then
LoggingService.Log(‘TserverExecute !’,[]);
if C = ‘TESTSTRING’ then
begin
AContext.Connection.Socket.Writeln(‘SENT’);
end;
end;

end.

Comments are closed.