Using buffers

Giganews Newsgroups
Subject: Using buffers
Posted by:  the bun (rosario.carbo…@btinternet.com)
Date: Mon, 1 Aug 2005

The problem I am having with bytes array (TIdBytes) is that for long response
like for example 200000 bytes the client is read just as a portion about in the middle,
whatever I set into RecvBufferSize, SendBufferSize.

BUFFER

Client buffer

        vUTF8String := UTF8Encode(pInputXML);
        SetLength(vBufferIn,length(vUTF8String));
        StringSize := Length(vUTF8String);
        for i := 0 to StringSize - 1 do
        begin
          vBufferIn[i] := Byte(vUTF8String[i+1]);
        end;
        FSocket.IOHandler.Write(vBufferIn);

        vUTF8String := '';
        BufferSize := 0;
        while (FSocket.Connected) do
        begin
          FSocket.IOHandler.CheckForDataOnSource(0);
          if not (FSocket.IOHandler.InputBufferIsEmpty) then
          begin
            BufferSize := FSocket.IOHandler.InputBuffer.Size;
            SetLength(vBufferOut,BufferSize);
            FSocket.IOHandler.ReadBytes(vBufferOut, BufferSize, false);
          end;
        end;
        vUTF8String := BytesToString(vBufferOut, 0, BufferSize);
        pOutPutXML := UTF8Decode(vUTF8String);

Server Buffer

      BufferSize := 0;
      vTET.Connection.IOHandler.CheckForDataOnSource(0);
      if not (vTET.Connection.IOHandler.InputBufferIsEmpty()) then
      begin
        BufferSize := vTET.Connection.IOHandler.InputBuffer.Size;
        SetLength(vBuffer,BufferSize);
        vTET.Connection.IOHandler.ReadBytes(vBuffer, BufferSize, False);
      end;
      vUTF8String := BytesToString(vBuffer, 0, BufferSize);
      vInputData := UTF8Decode(vUTF8String);
      ..................................................................
      vUTF8String := UTF8Encode(vOutputXML);
      SetLength(vBuffer,length(vUTF8String));
      for i:=0 to length(vUTF8String) -1 do
      begin
        vBuffer[i] := Byte(vUTF8String[i+1]);
      end;
      IOHandler.WriteDirect(vBuffer); { Write makes the same }

P.S.

What I am doing wrong with this code?

Please help!!!!!!

Regards

Rosario Carbone

Replies