Delphi 2009, Indy 10, TIdTCPServer.OnExecute, how to grab all the bytes in the InputBuffer

后端 未结 2 1179
借酒劲吻你
借酒劲吻你 2020-12-25 10:08

I am messing around with the Indy 10 supplied with Delphi 2009 and am having trouble with getting all the data from the IOHandler when OnExecute fires...

pro         


        
2条回答
  •  悲&欢浪女
    2020-12-25 10:53

    You should not be using Readable() like that. Try the following instead:

    procedure TFormMain.IdTCPServerExecute(AContext: TIdContext);
    var
      RxBuf: TIdBytes;
    begin
      RxBuf := nil;
      with AContext.Connection.IOHandler do
      begin
        CheckForDataOnSource(10);
        if not InputBufferIsEmpty then
        begin
          InputBuffer.ExtractToBytes(RxBuf);
          // process RxBuf as needed...
        end;
      end;
    end;
    

    Alternatively:

    procedure TFormMain.IdTCPServerExecute(AContext: TIdContext);
    var
      RxBufStr: String; // not UTF8String
    begin
      with AContext.Connection.IOHandler do
      begin
        CheckForDataOnSource(10);
        if not InputBufferIsEmpty then
        begin
          RxBufStr := InputBuffer.Extract(-1, enUtf8);
    
          // Alternatively to above, you can set the
          // InputBuffer.Encoding property to enUtf8
          // beforehand, and then call TIdBuffer.Extract()
          // without any parameters.
          //
          // Or, set the IOHandler.DefStringEncoding
          // property to enUtf8 beforehand, and then
          // call TIdIOHandler.InputBufferAsString()
    
          // process RxBufStr as needed...
        end;
      end;
    end;
    

    As for TIdSchedulerOfFiber - the SuperCore package is effectively dead at this time. It has not been worked on in a very long time, and is not up-to-date with the latest Indy 10 architecture. We may try to resurrect it at a later date, but it is not in our plans for the near future.

提交回复
热议问题