简体   繁体   中英

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.

I am not sure where to expect the output.

The documentation for IFMXLoggingService.Log() says:

Displays a message in the Event Log .

The Event Log is a window inside the IDE itself (View > Debug Windows > Event Log). It displays log messages generated by an app during a debugging session. So, you need to run your Firemonkey app inside the debugger in order to see the log messages from IFMXLoggingService .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM