Article View: borland.public.cppbuilder.internet.socket
Article #548Re: Using TIdTCPServer
From: Remy Lebeau (TeamB)
Date: Wed, 16 Jan 2008 18:06
Date: Wed, 16 Jan 2008 18:06
42 lines
2736 bytes
2736 bytes
"Peter" <piotrtrzeciak@yahoo.com> wrote in message
news:478e1c34$1@newsgroups.borland.com...
> pStream = new TIdTCPStream(AContext->Connection);
> msg = pStream->Read(imageData->rcv_buffer, 20);
You don't need to use a TIdTCPStream like that. In fact, that class is
primarily meant for Indy's internal use. TIdIOHandler has its own reading
methods that you should use instead, ie:
TIdBytes rcv_buffer;
AContext->Connection->IOHandler->ReadBytes(rcv_buffer, 20);
> discards it, then reads two bytes to see how long the remaining
> transmission is:
> msg = pStream->Read(imageData->rcv_buffer, 2);
Use the IOHandler's ReadSmallInt() method instead:
calculated_length = AContext->Connection->IOHandler->ReadSmallInt();
AContext->Connection->IOHandler->ReadBytes(rcv_buffer,
calculated_length);
> Now, the first two reads come back ok, but then the calculated length
> is different on each connection (and it's the same client, so I assume it
> should be the same), and the last read never comes back (that length is
> usually very large, like 40k+)
Sounds like you are not taking endian into account. Is the client sending
the 2-byte length value in host byte order or network byte order? It makes
a big difference. If you don't process it in the correct byte order, you
will end up with the wrong value, potentially telling Indy to expect more
data than is actually sent.
By default, ReadSmallInt() (and all of the other numeric reading methods)
expects the value to arrive in network byte order and converts it to host
byte order before exiting. You can set the AConvert parameter to false to
skip that step if needed.
Gambit
Technical Details
Message-ID:
<478e4760@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<478e1c34$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> Subject: Re: Using TIdTCPServer Date: Wed, 16 Jan 2008 10:06:54 -0800 Lines: 44 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: <478e4760@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1200506720 207.178.157.90 (16 Jan 2008 10:05:20 -0700) Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!feeder1-2.proxad.net!proxad.net!feeder1-1.proxad.net!club-internet.fr!feedme-small.clubint.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail