Indy Tidcmdtcpserver阅读垃圾

发布于 2025-02-10 07:08:48 字数 3730 浏览 1 评论 0原文

我正在实施一个非常简单的tidcmdtcpserver,用于从我们也写过的手机应用程序中接收数据。单元应用程序以简单的 Hello 命令开始,但是OnBeForeCommandHandler带有垃圾。

adata等于'SomerandomChars Hello'

随机字符是非ASCII。

我正在使用Delphi 2007与捆绑的Indy 10.1.5组件。我已经尝试过:

  • 也许我的程序正在造成一些腐败,所以我做了一个非常简单的 一个只有一个表单和tidcmdtcpserver。相同的结果。
  • Delphi 2007 Indy组件是否有货物?我切换到Delphi 10.3。同样的问题。
  • 我的计算机是否以某种方式破坏了通信?我在其他Windows 10中运行了简单的程序,无论是物理和虚拟的。有同样的问题。
  • 也许该单元格应用程序发送了错误的数据。尝试使用腻子直接发送命令。没有运气。
  • 不同的端口?同样,

我搜索了这个问题,但没有找到一个页面。实际上,它们都声明运行tidcmdtcpserver顺利进行。

最奇怪的一点是,在五个或六个命令之后,数据读取不错。在每个事件中,随机字符与前一个炭都是不同的。踏入Indy代码后,我发现它即将读取第一个时间时,它已经在输入缓冲区中具有随机字符。不同的“命令”需要不同数量的周期才能开始阅读而无需垃圾。对于“ Hello”,八到九次(并非总是相同)。

是什么原因造成的?我刚刚开始使用:

IdCmdTCPServer1.Active := True;

它需要单独的线程吗? Indy的帮助并不对此一言不发。从默认情况下没有更改属性。

这是简单应用程序的代码:

unit test;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer,
  IdCmdTCPServer, IdCommandHandlers, IdContext, IdServerIOHandler,
  IdServerIOHandlerSocket, IdServerIOHandlerStack;

type
  TForm1 = class(TForm)
    cmdsMain: TIdCmdTCPServer;
    ioshMain: TIdServerIOHandlerStack;
    procedure FormShow(Sender: TObject);
    procedure cmdsMainCommandHandlers0Command(ASender: TIdCommand);
    procedure cmdsMainBeforeCommandHandler(ASender: TIdCmdTCPServer;
      var AData: string; AContext: TIdContext);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.cmdsMainBeforeCommandHandler(ASender: TIdCmdTCPServer;
  var AData: string; AContext: TIdContext);
begin
// here comes the garbagge
end;

procedure TForm1.cmdsMainCommandHandlers0Command(ASender: TIdCommand);
begin
//
end;

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

end.
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 299
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object cmdsMain: TIdCmdTCPServer
    Bindings = <
      item
        IP = '0.0.0.0'
        Port = 55
      end>
    DefaultPort = 55
    IOHandler = ioshMain
    CommandHandlers = <
      item
        CmdDelimiter = ' '
        Command = 'hello'
        Disconnect = False
        Name = 'TIdCommandHandler0'
        NormalReply.Code = '200'
        ParamDelimiter = ' '
        ParseParams = True
        Tag = 0
        OnCommand = cmdsMainCommandHandlers0Command
      end>
    ExceptionReply.Code = '500'
    ExceptionReply.Text.Strings = (
      'Unknown Internal Error')
    Greeting.Code = '200'
    Greeting.Text.Strings = (
      'Welcome')
    HelpReply.Code = '100'
    HelpReply.Text.Strings = (
      'Help follows')
    MaxConnectionReply.Code = '300'
    MaxConnectionReply.Text.Strings = (
      'Too many connections. Try again later.')
    ReplyTexts = <>
    ReplyUnknownCommand.Code = '400'
    ReplyUnknownCommand.Text.Strings = (
      'Unknown Command')
    OnBeforeCommandHandler = cmdsMainBeforeCommandHandler
    Left = 312
    Top = 152
  end
  object ioshMain: TIdServerIOHandlerStack
    Left = 376
    Top = 168
  end
end

Update :我们修改了单元应用程序以将命令发送到Echo服务器:TCPBIN.com。回声被罚款。我们使用Putty将单元格绘制到同一家服务器上,以确保它正在生成任何垃圾。在这两种情况下,它都很好。

I'm implementing a very simple TIdCmdTCPServer for receiving data from a cell phone application we also wrote. The cell application starts with a simple hello command, but the OnBeforeCommandHandler comes with garbage.

AData equals 'somerandomchars hello'

The random chars are non ASCII ones.

I'm using Delphi 2007 with the bundled Indy 10.1.5 components. I've tried this:

  • Maybe my program was creating some corruption so I made a very simple
    one with just a Form and a TIdCmdTCPServer. Same result.
  • Are the Delphi 2007 Indy components buggy? I switched to Delphi 10.3. Same problem.
  • Is my computer somehow corrupting the communication? I ran the simple program in other Windows 10, both physical and virtual. Got the same problem.
  • Maybe the cell application was sending wrong data. Tried using Putty to send the commands directly. No luck.
  • Different port? Same

I've searched for this problem but found not a single page. In fact, they all state running a TIdCmdTCPServer smoothly.

The most strange point is that after five or six commands, the data reads fine. On each event, the random chars are distinct from the previous one. After stepping through Indy code, I discovered that when it is about to read the very first time, it already has the random chars in the input buffer. Different "commands" need a different amount of cycles to begin reading without garbage. In the case of "hello", eight or nine times (not always the same).

What is causing this? I'm just starting the server with:

IdCmdTCPServer1.Active := True;

Does it need a separate thread? Indy's help doesn't say anything about that. No properties have been changed from the default ones.

Here is the code of the simple application:

unit test;

interface

uses
  Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
  Dialogs, IdBaseComponent, IdComponent, IdCustomTCPServer, IdTCPServer,
  IdCmdTCPServer, IdCommandHandlers, IdContext, IdServerIOHandler,
  IdServerIOHandlerSocket, IdServerIOHandlerStack;

type
  TForm1 = class(TForm)
    cmdsMain: TIdCmdTCPServer;
    ioshMain: TIdServerIOHandlerStack;
    procedure FormShow(Sender: TObject);
    procedure cmdsMainCommandHandlers0Command(ASender: TIdCommand);
    procedure cmdsMainBeforeCommandHandler(ASender: TIdCmdTCPServer;
      var AData: string; AContext: TIdContext);
  private
    { Private declarations }
  public
    { Public declarations }
  end;

var
  Form1: TForm1;

implementation

{$R *.dfm}

procedure TForm1.cmdsMainBeforeCommandHandler(ASender: TIdCmdTCPServer;
  var AData: string; AContext: TIdContext);
begin
// here comes the garbagge
end;

procedure TForm1.cmdsMainCommandHandlers0Command(ASender: TIdCommand);
begin
//
end;

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

end.
object Form1: TForm1
  Left = 0
  Top = 0
  Caption = 'Form1'
  ClientHeight = 299
  ClientWidth = 635
  Color = clBtnFace
  Font.Charset = DEFAULT_CHARSET
  Font.Color = clWindowText
  Font.Height = -11
  Font.Name = 'Tahoma'
  Font.Style = []
  OldCreateOrder = False
  OnShow = FormShow
  PixelsPerInch = 96
  TextHeight = 13
  object cmdsMain: TIdCmdTCPServer
    Bindings = <
      item
        IP = '0.0.0.0'
        Port = 55
      end>
    DefaultPort = 55
    IOHandler = ioshMain
    CommandHandlers = <
      item
        CmdDelimiter = ' '
        Command = 'hello'
        Disconnect = False
        Name = 'TIdCommandHandler0'
        NormalReply.Code = '200'
        ParamDelimiter = ' '
        ParseParams = True
        Tag = 0
        OnCommand = cmdsMainCommandHandlers0Command
      end>
    ExceptionReply.Code = '500'
    ExceptionReply.Text.Strings = (
      'Unknown Internal Error')
    Greeting.Code = '200'
    Greeting.Text.Strings = (
      'Welcome')
    HelpReply.Code = '100'
    HelpReply.Text.Strings = (
      'Help follows')
    MaxConnectionReply.Code = '300'
    MaxConnectionReply.Text.Strings = (
      'Too many connections. Try again later.')
    ReplyTexts = <>
    ReplyUnknownCommand.Code = '400'
    ReplyUnknownCommand.Text.Strings = (
      'Unknown Command')
    OnBeforeCommandHandler = cmdsMainBeforeCommandHandler
    Left = 312
    Top = 152
  end
  object ioshMain: TIdServerIOHandlerStack
    Left = 376
    Top = 168
  end
end

UPDATE: We modified the cell app to just send the commands to an echo server: tcpbin.com. The echo was received fine. We emulated the cell to the same server using Putty just to ensure that it was generating any garbage. In both, it ran fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

梦太阳 2025-02-17 07:08:48

您可以通过多个Indy版本和多个服务器计算机重现问题的事实告诉我,问题根本不是服务器,而是客户端。例如,如果您在telnet模式下使用腻子而不是原始模式。

The fact that you can reproduce the issue across multiple Indy versions and multiple server machines tells me the problem is likely not with the server at all, but with the client. For instance, if you are using Putty in telnet mode instead of raw mode.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文