Delphi 一段时间后,TIdTcpServer停止接受新连接

Delphi 一段时间后,TIdTcpServer停止接受新连接,delphi,indy10,Delphi,Indy10,我已经尝试使用TIdTcpServer很多次了,我总是遇到同样的问题。 工作(接收连接)一段时间后,他停止接收新连接,需要重新启动他以进行后续工作 我现在使用的代码非常简单,但问题仍然存在。我不知道还能做什么,我几乎要买一个连接框架,看看是否能解决这个问题 procedure TForm1.ClientStateUpdated(Client: TClient; Texto: String); var PeerIP, HostName: string; begin PeerIP :=

我已经尝试使用TIdTcpServer很多次了,我总是遇到同样的问题。 工作(接收连接)一段时间后,他停止接收新连接,需要重新启动他以进行后续工作

我现在使用的代码非常简单,但问题仍然存在。我不知道还能做什么,我几乎要买一个连接框架,看看是否能解决这个问题

procedure TForm1.ClientStateUpdated(Client: TClient; Texto: String);
var
  PeerIP, HostName: string;
begin
  PeerIP    := Client.IP;
  HostName  := Client.HWID;

  TThread.Queue(nil,
  procedure
  begin
    if ((PeerIP <> '') and (HostName <> '')) then Memo2.Lines.Add(Format(Texto, [TimeToStr(Now), PeerIP, HostName]));
  end);
end;

procedure TForm1.IdTCPServer1Connect(AContext: TIdContext);
var
  Conexao : TClient;
  Retorno : TArray<String>;
  Query   : TFDQuery;
  Libera  : Boolean;
  IPEX    : Boolean;
begin
  Libera  := True;
  IPEX    := True;
  Conexao := TClient(AContext);
  Retorno := AContext.Connection.IOHandler.ReadLn(LF, 5000).Split(['#']);

  if Length(Retorno) = 0 then
  begin
    AContext.Connection.Disconnect;
    Exit;
  end;

  if Retorno[0] = 'cmdPing' then Retorno[1] := Retorno[2];

  Conexao.IP          := AContext.Connection.Socket.Binding.PeerIP;
  Conexao.HWID        := Retorno[1];
  Conexao.Connected   := Now;
  Conexao.Ping        := Ticks;

  ClientStateUpdated(Conexao, "%s %s %s");
  Conexao.Connection.IOHandler.WriteLn('cmdContinue');
end;

procedure TForm1.IdTCPServer1Disconnect(AContext: TIdContext);
begin
  ClientStateUpdated(TClient(AContext), RetornaTraducao(32));
end;

procedure TForm1.IdTCPServer1Execute(AContext: TIdContext);
var
  Conexao       : TClient;
  Retorno       : TArray<String>;
begin
  Conexao := TClient(AContext);
  Retorno := AContext.Connection.IOHandler.ReadLn.Split(['#']);
end;
奇怪的是,如果我创建一个连接/断开连接并运行数小时的应用程序,该应用程序工作正常,但当我将其公开发布时,问题就出现了


我不使用IdSchedulerOfThreadDefault1/IdSchedulerOfThreadPool1

这几乎不是一个问题,因此很难准确诊断问题所在。
retronatraducao()
做什么?如何使用
TClient.(Un)Lock()
?我看不出这些代码会如何影响服务器接受连接的能力,这种情况发生在一个单独的线程上,而不是在每个
TClient
运行的线程上。这是所有来自服务器的代码,我只需获取字符串“%s%s”就可以了。关于锁定/解锁,我不使用了。我应该如何使用它,在哪里?我已经更新了主题,删除了retronatraduco并替换为“%s%s%s”,他就是他所得到的我创建了一个应用程序,在这里连接/断开连接,现在正在测试大约80k的连接/断开连接,工作正常,但由于某些原因,当我公开发布时,这个问题会发生“当我公开发布时,这个问题会发生”-这告诉我们绝对没有什么用处。到目前为止,我没有看到您所展示的代码中有任何明显的东西会导致此问题。所以它必须是在代码中,您还没有显示。您只需要在出现故障的系统上调试代码。我应该如何使用(Un)Lock()?因为我不使用它,代码只是我在这里写的那个人,没有别的。
type
  TClient = class(TIdServerContext)
    private
      FCriticalSection  : TCriticalSection;
    public
      IP          : String;
      HWID        : String;

      Connected   : TDateTime;
      Ping        : Cardinal;   
      Queue       : TIdThreadSafeStringList;

      constructor Create(AConnection: TIdTCPConnection; AYarn: TIdYarn; AList: TIdContextThreadList = nil); override;
      destructor  Destroy; override;
      procedure   Lock;
      procedure   Unlock;
  end;

constructor TClient.Create(AConnection: TIdTCPConnection; AYarn: TIdYarn; AList: TIdContextThreadList = nil);
begin
  inherited Create(AConnection, AYarn, AList);

  FCriticalSection  := TCriticalSection.Create;
  Queue             := TIdThreadSafeStringList.Create;
end;

destructor TClient.Destroy;
begin
  Queue.Free;
  FreeAndNil(FCriticalSection);

  inherited;
end;

procedure TClient.Lock;
begin
  FCriticalSection.Enter;
end;

procedure TClient.Unlock;
begin
  FCriticalSection.Leave;
end;