🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: indy tcp server

#4349
From: Remy Lebeau (TeamB)
Date: Mon, 14 Feb 2005 21:30
57 lines
2722 bytes
"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: <42111797$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <42110245$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: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <42110245$1@newsgroups.borland.com>
Subject: Re: indy tcp server
Date: Mon, 14 Feb 2005 13:30:27 -0800
Lines: 59
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: <42111797$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1108416407 68.69.17.41 (14 Feb 2005 13:26:47 -0800)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!proxad.net!212.101.4.254.MISMATCH!solnet.ch!solnet.ch!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail