🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: indy tcp server

#4350
From: Jonathan Benedicto
Date: Mon, 14 Feb 2005 21:46
69 lines
3133 bytes
Thank you very much for this help.

-- 
Jonathan

"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message 
news:42111797$1@newsgroups.borland.com...
>
> "Jonathan Benedicto" <incorrect@no.server> wrote in message
> news:42110245$1@newsgroups.borland.com...
>
>> Eg. If I read data like this :
>
> You should not be looping like that.  The OnExecute event is already 
> looped
> by TIdTCPServer.  Your code should only be processing a single iteration 
> of
> that internal loop, not running your own loop at all:
>
>    void __fastcall TForm1::IdTCPServer1Connect(TIdPeerThread *AThread)
>    {
>        AThread->Connection->ReadTimeout = 1000;
>    }
>
>    void __fastcall TForm1::IdTCPServer1Execute(TIdPeerThread *AThread)
>    {
>        char buffer[200];
>
>        if( AThread->Connection->InputBuffer->Size == 0 )
>        {
>            int read = AThread->Connection->ReadFromStack(true,
> IdTimeoutDefault, false);
>            if( read == -1 ) // timeout
>                return;
>        }
>
>        do
>        {
>            int bufsize = min(AThread->Connection->InputBuffer->Size, 200);
>            AThread->Connection->ReadBuffer(buffer, bufsize);
>            // use buffer as needed...
>        }
>        while( bufsize > 0 );
>    }
>
>> Then the app can only work with 200 bytes chucks of data. Even if the
>> sending app sent a 100 byte chunk and then a 300 byte chunk.
>
> I would strongly recommend that you prefix your packets with the actual 
> size
> of the packets.  Then you don't have to limit your buffer size during
> reading, and can send small and large packets alike:
>
>    void __fastcall TForm1::IdTCPServer1Execute(TIdPeerThread *AThread)
>    {
>        int size = AThread->Connection->ReadInteger(true);
>        if( size > 0 )
>        {
>            char *buffer = new char[size];
>            AThread->Connection->ReadBuffer(buffer, size);
>            // use buffer as needed...
>            delete[] buffer;
>        }
>    }
>
>
> Gambit
>
> 
Technical Details
Message-ID: <42111c4c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail
References: <42110245$1@newsgroups.borland.com> <42111797$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,3835546c79abd997
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: <42110245$1@newsgroups.borland.com> <42111797$1@newsgroups.borland.com>
Subject: Re: indy tcp server
Date: Mon, 14 Feb 2005 16:46:54 -0500
Lines: 71
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.2527
X-MIMEOLE: Produced By Microsoft MimeOLE V6.00.2900.2527
X-RFC2646: Format=Flowed; Original
NNTP-Posting-Host: 69.158.108.120
Message-ID: <42111c4c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1108417612 69.158.108.120 (14 Feb 2005 13:46:52 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail