首页 > 解决方案 > Indy 多端口 tcp 未在特定端口接收数据

问题描述

我有一个 TCP 服务器来从一些不同的端口读取数据。

端口 55000 连接到硬件设备,但其他端口将从软件客户端获取数据。

我的代码如下所示。

除 55000 外的所有端口都运行良好,但我没有在 55000 上获得任何数据。Wire-Shark 显示 TCP 层上的一切正常,Math-Lab 软件也可以接收数据,但 Indy 不能。

我怎样才能找到并解决问题?

ccsReCStatus := false;
offReCStatus := false;
case AContext.Binding.Port of
      55000: begin
              repeat
                  aByte := AContext.Connection.IOHandler.ReadByte;
                  inputOfflineStr := inputOfflineStr + chr(aByte);
                  if inputOfflineStr.Length>1000 then
                  begin
                    TThread.Synchronize(
                    nil,
                    procedure
                      begin
                          Memo14.Lines.Add( inputOfflineStr );
                          inputOfflineStr:='';
                      end);
                    end;
              until offReCStatus = true;
      end;
      35758: begin
            inputCcsStr :='';
            repeat
                  aByte := AContext.Connection.IOHandler.ReadByte;
                  if aByte=$C0 then
                  begin
                      TThread.Synchronize(
                      nil,
                      procedure
                      begin
                          memo14.Lines.Add( datetimetostr(now) + ' :' + inputCcsStr );
                          inputCcsStr:='';
                      end);
                  end
                  else
                  begin
                      inputCcsStr := inputCcsStr +  aByte.ToHexString;
                      AbLED482.Tag := DateTimeToUnix(now);
                      AbLED482.Checked := true;
                  end;
            until ccsReCStatus = true;
      end;
      2222: begin
            RStr:='';
          repeat
                aByte := AContext.Connection.IOHandler.ReadByte;
                if (aByte = $C0) and (RStr='') then
                begin
                  RStr:='';
                end
                else
                if (aByte = $C0) and (RStr<>'') then
                begin
                  TThread.Synchronize(
                  nil,
                  procedure
                  begin
                       memo14.Lines.Add( RStr );
                       RStr := '';
                  end);
                end
                else
                begin
                    RStr:=RStr+chr(aByte);
                end;
          until ccsReCStatus = true;
        end;
end;

标签: delphitcpindytcpserverdelphi-10.3-rio

解决方案


推荐阅读