Article View: borland.public.cppbuilder.internet.socket
Article #563Re: Using TIdTCPServer
From: Remy Lebeau (TeamB)
Date: Thu, 24 Jan 2008 17:48
Date: Thu, 24 Jan 2008 17:48
47 lines
2950 bytes
2950 bytes
"Peter" <piotrtrzeciak@yahoo.com> wrote in message
news:4798a5e1$1@newsgroups.borland.com...
> The original code was very simple:
<snip>
Your original code was reading endlessly, as TIdTCPStream::Read() always
returns the same Count value that you pass in, so imageData->msg would
always be greater than 0 until an exception occured. Such logic is easy to
reproduce using the code I already gave you earlier:
while( imageData->msg > 0 )
{
// assuming rcv_buffer is a TIdBytes. ReadBytes() will not exit
until all 32000
// bytes have been received. The same was true for
TIdTCPStream::Read() as well...
AContext->Connection->IOHandler->ReadBytes(imageData->rcv_buffer,
32000);
imageData->msg = 32000;
fwrite(&imageData->rcv_buffer[0], imageData->msg, 1,
imageData->imgFile);
}
> but now, I'm trying this:
<snip>
> and I get no data from the socket.
Then your client is not sending any data at all, or is more likely sending
data after a small delay. You are exiting your loop if the InputBuffer has
no data each time you check it. The first time you check the InputBuffer,
if no data has arrived yet, you exit the loop right away. At the very
least, you should increase your timeout value to give the data a better
chance of catching up to how fast your reading code is running.
With that said, the best option is to forget looping at all. Have the
client send the data size before sending the actual data. Then your server
knows exactly how many bytes to expect, and can call ReadBytes() or
ReadStream() just once to do all of the work. In fact, that is what you
said in your original posting that you were doing, but you are not doing
that anymore in this latest code snippet. So by introducing InputBuffer
checking into your code, which you did not need in the first place, you have
made the code operate worse, not better.
Gambit
Technical Details
Message-ID:
<4798cf30$1@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<478e1c34$1@newsgroups.borland.com> <478e4760@newsgroups.borland.com> <4798a5e1$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,452e664b18b0b56c X-Google-Attributes: gid11508e,public,usenet X-Google-Language: ENGLISH,ASCII-7-bit From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <478e1c34$1@newsgroups.borland.com> <478e4760@newsgroups.borland.com> <4798a5e1$1@newsgroups.borland.com> Subject: Re: Using TIdTCPServer Date: Thu, 24 Jan 2008 09:48:17 -0800 Lines: 49 Organization: Lebeau Software X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2900.3138 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3198 X-RFC2646: Format=Flowed; Original NNTP-Posting-Host: 207.178.157.90 Message-ID: <4798cf30$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1201196848 207.178.157.90 (24 Jan 2008 09:47:28 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail