Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: Open a TCP Socket

www.cryer.info
Managed Newsgroup Archive

Re: Open a TCP Socket

Subject:Re: Open a TCP Socket
Posted by:"Remy Lebeau (TeamB)" (no.spam@no.spam.com)
Date:Tue, 5 Feb 2008 10:43:20

"Kim Jensen" <kim@comcasystems.com> wrote in message
news:47a8a55b$1@newsgroups.borland.com...

> I posted the Winshark file at the  "borland.public.attachments" newsgroup.

Fair enough.  My earlier assessment still stands.  The terminating ':' at
the end of a reply does not have a CRLF, but the data lines preceeding it
do.  So you will have to take that into account when reading the reply, as I
showed you earlier:

    procedure TMyForm.ReadReply(AReply: TStrings = nil);
    var
        B: Byte;
        Line: String;
    begin
        if AReply <> nil then AReply.Clear;
        with IdTCPClient.IOHandler do
        begin
            repeat
                while InputBuffer.Size = 0 do
                begin
                    ReadFromSource(False);
                    CheckForDisconnect(True, True);
                end;
                B := InputBuffer.PeekByte(0);
                if (B = Ord(':')) or (B = Ord('?')) then
                begin
                    // end of reply, remove it from the buffer ...
                    InputBuffer.Remove(1);
                    if B = Ord('?') then raise Exception.Create('failed');
                    Exit;
                end;
                Line := IdTCPClient.IOHandler.ReadLn;
                if AReply <> nil then AReply.Add(Line);
            until False;
        end;
    end;

Looking at it again, you can probably simplify it to a single ReadLn() call,
provided that the reply data can never contain an embedded ':' in it:

    procedure TMyForm.ReadReply(AReply: TStrings = nil);
    var
        Data: String;
    begin
        if AReply <> nil then AReply.Clear;
        with IdTCPClient.IOHandler do
        begin
            while InputBuffer.Size = 0 do
            begin
                ReadFromSource(False);
                CheckForDisconnect(True, True);
            end;
            if InputBuffer.PeekByte(0) = Ord('?') then
            begin
                // error reply, remove it from the buffer and exit ...
                InputBuffer.Remove(1);
                raise Exception.Create('failed');
            end;
            // assume a successful reply, look for the terminating ':' ...
            Data := ReadLn(':');
            if AReply <> nil then AReply.Text := Data;
        end;
    end;


Gambit

Replies:

none

In response to:

www.cryer.info
Managed Newsgroup Archive