简体   繁体   English

调试Delphi Firemonkey Indy TCP服务器

[英]Debugging Delphi Firemonkey Indy TCP Server

I have a Delphi Firemonkey application implementing a TCP server. 我有一个实现TCP服务器的Delphi Firemonkey应用程序。 The server is not opening the port as expected. 服务器未按预期打开端口。 I can see the form open but netstat reveals that the port is not opened. 我可以看到该窗体已打开,但netstat显示该端口未打开。 I am now attempting to debug this issue by trying to put log messages. 我现在正尝试通过尝试放置日志消息来调试此问题。

The trouble is I have never used Firemonkey before. 问题是我以前从未使用过Firemonkey。 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. 然后在函数Tserver.Execute调用它,以确保它已执行。

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: IFMXLoggingService.Log()的文档说:

Displays a message in the Event Log . 事件日志中显示一条消息。

The Event Log is a window inside the IDE itself (View > Debug Windows > Event Log). 事件日志是IDE本身内部的一个窗口(“查看”>“调试Windows”>“事件日志”)。 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 . 因此,您需要在调试器中运行Firemonkey应用程序,才能查看来自IFMXLoggingService的日志消息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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