Hi,

I am using D7 and ICS v5 on a Server / Client project.
The client can send something like :
   100 REQUEST HELP {somecommand}

and the server can answer with a small text, or a large one. In my example, 
there's a
104 kbytes file. Not very large, but large enough to trigger several 
DataAvailable
events.

I searched some examples, but most of them use LineMode and LineLimit. I'm 
afraid
that's not an option.
So I wrote the following code, but I'm still lost:

procedure TMyClient.Event_DataAvailabe( Sender : TObject; Error : Word );
const
   BufSize = 4096;
var
   zBuf : Array[0..BufSize-1] of Ansichar;
   Len  : Integer;

begin
    { Remember: we use line mode. We will always receive complete lines     }
    with Sender as TWSocket do
         Len := Receive(@zBuf, BufSize );

    // here I expect "Len" <= BufSize. If it's equal than "may be" there's more 
to
    // read. How can I be sure? Does ICS have some internal flag ?


    if Len = 0 then begin
       // Something happened!! What?
        Exit;
    end;

    if Len=-1 then begin
       // Seems to be the end of a long string. Once len = -1, can
       // this event be fired again?
       exit
    end;


    // Now the problem:
    // I must cache the received zBuf
    FRcvBuf := FRcvBuf+ string(zBuf);

    // If we read all the data, we display it
    if {Some condition met} then begin
       DisplayMemo.Lines.Add(FRcvBuf );
       FRcvBuf := '';
    end;
end;

Am I on the right track?
Can somebody help me?

TIA,
Clément
-- 
To unsubscribe or change your settings for TWSocket mailing list
please goto http://www.elists.org/mailman/listinfo/twsocket
Visit our website at http://www.overbyte.be

Reply via email to