🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #3095

Re: Indy TCP "Wait for Reply"

#3095
From: Remy Lebeau (TeamB)
Date: Thu, 17 Nov 2005 18:08
68 lines
2862 bytes
"Darlington ADIBE" <bcb@triative.com> wrote in message
news:437c328b@newsgroups.borland.com...

> Any profession advice on how to implement this "wait for reply" issue

Indy already implements all of that for you.  Simply read from the socket
immediately after you write to it.  The reading will not return until data
is actually received, or a timeout/error occurs.  For example:

    HRESULT __stdcall TMyComObjImpl::Authenticate(BSTR uid, BSTR pwd)
    {
        try
        {
            AnsiString Cmd;
            AnsiString Response;
            AnsiString Status;

            Cmd.sprintf("#AUTHEN#%s#%s#", AnsiString(uid).c_str(),
AnsiString(pwd).c_str());

            TCPClient->Connect(5000);
            try
            {
                TCPClient->WriteLn(Cmd);
                Response = TCPClient->ReadLn(LF, IdTimeoutDefault; -1);

                Response.Delete(1,1);
                if( Fetch(Response, "#") != "AUTHEN" )
                    throw Exception("Unknown response");

                Status = Fetch(Response, "#");
                if( Status != "OK" )
                {
                    if( Status == "ERR" )
                        throw Exception("Authentication failed: " +
Fetch(Response, "#"));
                    else
                        throw Exception("Unknown response");
                }
            }
            catch(const Exception &)
            {
                TCPClient->Disconnect();
                throw;
            }
        }
        catch(const Exception &e)
        {
            return Error(e.Message, IID_IMyComObj);
        }
        return S_OK;
    }

    HRESULT __stdcall TMyComObjImpl::get_RTimeout(long *Result)
    {
        *Result = TCPClient->ReadTimeout;
        return S_OK;
    }

    HRESULT __stdcall TMyComObjImpl::set_RTimeout(long Value)
    {
        TCPClient->ReadTimeout = Value;
        return S_OK;
    }


Gambit
Technical Details
Message-ID: <437cc79a$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <437c328b@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,187f889f070be6a7
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <437c328b@newsgroups.borland.com>
Subject: Re: Indy TCP "Wait for Reply"
Date: Thu, 17 Nov 2005 10:08:18 -0800
Lines: 70
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2800.1409
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409
NNTP-Posting-Host: 68.69.17.41
Message-ID: <437cc79a$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1132251034 68.69.17.41 (17 Nov 2005 10:10:34 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!border1.nntp.dca.giganews.com!nntp.giganews.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail