Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Oct : Re: Funny error TCPclient

www.cryer.info
Managed Newsgroup Archive

Re: Funny error TCPclient

Subject:Re: Funny error TCPclient
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Fri, 13 Oct 2006 15:01:42

"GannTrader" <a@a.com> wrote in message
news:453005e7@newsgroups.borland.com...

>    if findyclient.Connected then  // ***If i skip this line then
> FIndyClient.IOHandler.InputBuffer.Size i always zero

Indy only reads data from the socket when the InputBuffer does not have
enough bytes to satisfy a reading operation.  Given the code you have shown,
you are not actually reading anything from the socket if you omit the call
to Connected(), so all pending data from the socket is never placed into the
IOHandler's InputBuffer.

To make your code work without explicitially calling Connected(), you have
to actually read something from the socket.  Since you are processing
arbitrary strings, you will have to call the CheckForDataOnSource() method
before then extracting the contents of the InputBuffer as a string.  For
example:

    procedure TMyReadThread.Read_Stack;
    begin
        FIndyClient.CheckForDataOnSource(IdTimeoutInfinite);
        message1 := FIndyClient.IOHandler.InputBufferAsString:
    end;

    procedure TMyReadThread.Execute;
    begin
        Connekt;
        while (not Terminated) do
        begin
            Read_Stack;
        end;
    end;

On the other hand, if your socket data actually has some structure to it,
then using the various reading methods of the IOHandler (if you call
ReadString(), you have to specify a non-zero length) will internally call
CheckForDataOnSource() to fill the InputBuffer accordingly.


Gambit

Replies:

In response to:

www.cryer.info
Managed Newsgroup Archive