🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: INDY IdTCPServer1 read bytes

#3379
From: Jonathan Benedicto
Date: Wed, 21 Sep 2005 16:48
77 lines
3307 bytes
"Billy Holliday" <NoSpam@Hohoho.com> wrote in message 
news:43312e17$1@newsgroups.borland.com...
> Is it possible to get the length of a received datapacked with INDY
> TidTCPServer ?

You can find out how much data the TCPServer has received since you last 
checked. For your app, something like this might work:

// Untested

void __fastcall TForm1::TcpServerExecute(TIdPeerThread *AThread)
{
        int StackRead;
        unsigned int DataSize;

        // Read data off the TCP connection.
        if(AThread->Connection->InputBuffer->Size == 0)
        {
                try
                {
                        StackRead = 
AThread->Connection->ReadFromStack(true, 1000, false);
                }
                catch( const Exception &E )
                {
                        StackRead = -1;
                }
                catch(...)
                {
                        StackRead = -1;
                }
        }
        else
        {
                StackRead = -1;
        }

        // Check that we have received data and that we are connected..
        if(StackRead > 0 && AThread->Connection)
        {
                DataSize = AThread->Connection->InputBuffer->Size;
                if(DataSize > 0)
                {
                        // I would suggest getting the boost library and 
not using raw pointers
                        // But this should work for now.
                        char response[20];

                        char *Data = new char[DataSize];

                        try
                        {
                            AThread->Connection->ReadBuffer(Data.get(), 
DataSize);

                            // Now Data contains the data received.
                            // And DataSize contains how much data was 
received.

                            // Process it here.

                            // Send your response.
                            AThread->Connection->WriteBuffer( response, 
strlen( response ), true );
                        }
                        __finally
                        {
                            delete[] Data;
                        }
                }
        }
}

However, as Mr Lebeau did point out, you probably will still have to 
disable Nagle.

Jonathan 
Technical Details
Message-ID: <43318e61$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.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: <43312e17$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,33f175a151104b01
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Jonathan Benedicto" <incorrect@no.server>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <43312e17$1@newsgroups.borland.com>
Subject: Re: INDY IdTCPServer1 read bytes
Date: Wed, 21 Sep 2005 12:48:03 -0400
Lines: 79
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2670
X-RFC2646: Format=Flowed; Original
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2670
NNTP-Posting-Host: 69.158.123.150
Message-ID: <43318e61$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1127321185 69.158.123.150 (21 Sep 2005 09:46:25 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news4.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