Article View: borland.public.cppbuilder.internet.socket
Article #4251Re: indy tcp server
From: Jonny Wilkinson
Date: Wed, 09 Mar 2005 17:10
Date: Wed, 09 Mar 2005 17:10
83 lines
3507 bytes
3507 bytes
Hi can i ask which version of indy has the
AThread->Connection->InputBuffer->Size properties.
On my C++ Builder 6, these aren't valid properties
Many thanks
Jonny
"Jonathan Benedicto" <incorrect@no.server> wrote in message
news:42111c4c$1@newsgroups.borland.com...
> 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:
<d0nall$sgp$1$830fa795@news.demon.co.uk>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mailReferences:
<42110245$1@newsgroups.borland.com> <42111797$1@newsgroups.borland.com> <42111c4c$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 Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!news.glorb.com!proxad.net!proxad.net!194.159.246.34.MISMATCH!peer-uk.news.demon.net!kibo.news.demon.net!news.demon.co.uk!demon!not-for-mail From: "Jonny Wilkinson" <jonny@nospam.jonnywilk.co.uk> Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: indy tcp server Date: Wed, 9 Mar 2005 17:10:10 -0000 Lines: 85 Message-ID: <d0nall$sgp$1$830fa795@news.demon.co.uk> References: <42110245$1@newsgroups.borland.com> <42111797$1@newsgroups.borland.com> <42111c4c$1@newsgroups.borland.com> NNTP-Posting-Host: 62.49.107.155 X-Trace: news.demon.co.uk 1110388214 29209 62.49.107.155 (9 Mar 2005 17:10:14 GMT) X-Complaints-To: abuse@demon.net NNTP-Posting-Date: Wed, 9 Mar 2005 17:10:14 +0000 (UTC) X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 X-Priority: 3 X-RFC2646: Format=Flowed; Response X-Newsreader: Microsoft Outlook Express 6.00.2900.2180 X-MSMail-Priority: Normal