Einzelnen Beitrag anzeigen

Kas Ob.

Registriert seit: 3. Sep 2023
412 Beiträge
 
#50

AW: schnelle Server Client Verbindung ohne Verluste

  Alt 8. Apr 2025, 13:36
Also try this
Delphi-Quellcode:
procedure TMyTCPServer.OnExecuteHandler(AContext: TIdContext);
var
  Buffer: TIdBytes;
begin
  // FLastContext := AContext; // if needed, yet how it is useful in multihtreaded server/application ?!
  // removed ReadingIsActiv , don't understand it usefulness

  if AContext.Connection.IOHandler.CheckForDataOnSource(10) then
  begin
      AContext.Connection.IOHandler.ReadBytes(Buffer, -1, False);
      if Length(Buffer) > 0 then
      begin
        Inc(FAnzEmpfang);
        Inc(FBytesEmpfang, Length(Buffer));
        FDataQueue.Enqueue(Buffer);

        TThread.Queue(nil, procedure
        begin
          TForm1(FForm).Log('Receive-Anzahl: ' + FAnzEmpfang.ToString);
          TForm1(FForm).Log('Receive-Bytes: ' + FBytesEmpfang.ToString);
          FAnzEmpfang := 0;
          FBytesEmpfang := 0;
        end);
      end;
  end;
end;
Simpler not blocking forever and still using the poll state but at 10ms, meaning at wrost case scenario it will be 100 times per second.
Kas
  Mit Zitat antworten Zitat