Re: indy tcp server


2005-03-10 01:10:10 AM
cppbuilder15
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" < XXXX@XXXXX.COM >wrote in message
Quote
Thank you very much for this help.

--
Jonathan

"Remy Lebeau (TeamB)" < XXXX@XXXXX.COM >wrote in message
news:42111797$ XXXX@XXXXX.COM ...
>
>"Jonathan Benedicto" < XXXX@XXXXX.COM >wrote in message
>news:42110245$ XXXX@XXXXX.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
>
>