Article View: borland.public.cppbuilder.internet.socket
Article #4273Re: TClientSocket ReceiveLength() returns large value
From: Gary Johnson
Date: Wed, 16 Mar 2005 15:41
Date: Wed, 16 Mar 2005 15:41
53 lines
3340 bytes
3340 bytes
i grabbed the code below in a post you suggested. this is the method i used
originally, and it had the same result. the data being transmitted by the
server (as being detected by a network analyzer) was always in packets less
than or equal to 1514 bytes.
you said "Only process packets when your buffer contains full packets." i
don't know what that means. how do i know whether or not i have received a
full packet? particularly in my problem case in which i have received
something larger than 1514.
int receivelength = Socket->ReceiveLength();
if ( receivelength > 0 )
{
int n_received = Socket->ReceiveBuf ( buf, receivelength );
//and n_received == receivelength always!
}
(posted by Hans.)
//----------------------------------
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message
news:423769e3$1@newsgroups.borland.com...
>
> "Gary Johnson" <gjohnson@cinele.com> wrote in message
> news:42375d21$1@newsgroups.borland.com...
>
> > on two different runs, the buffer size was 2760 and 5840 bytes.
>
> Was that much data actually being transmitted to begin with? Those look
> like reasonable amounts of data for socket packets.
>
> > bufferLengthInBytes = Socket->ReceiveLength();
> > while(bufferLengthInBytes < Socket->ReceiveLength())
> > bufferLengthInBytes = Socket->ReceiveLength();
>
> That is not the correct way to handle things! You should only be calling
> ReceiveLength() *once*, and then reading however many bytes it says are
> actually available, and then exit the event handler, waiting for the event
> to be triggered again later to read more data. If you do not read a full
> packet, then you must buffer whatever data you did read, and then wait for
> the event to be triggered again to add more data to the buffer. Only
> process packets when your buffer contains full packets. Please go to
> http://www.deja.com and do a search through the newsgroup archives.
Sample
> code for proper buffering has been posted many times before.
>
>
> Gambit
>
>
Technical Details
Message-ID:
<42385392$3@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mailReferences:
<4235f30d@newsgroups.borland.com> <4235f764$2@newsgroups.borland.com> <42375d21$1@newsgroups.borland.com> <423769e3$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,d813a4525d839272 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Reply-To: "Gary Johnson" <gjohnson@cinele.com> From: "Gary Johnson" <gjohnson@cinele.com> Newsgroups: borland.public.cppbuilder.internet.socket References: <4235f30d@newsgroups.borland.com> <4235f764$2@newsgroups.borland.com> <42375d21$1@newsgroups.borland.com> <423769e3$1@newsgroups.borland.com> Subject: Re: TClientSocket ReceiveLength() returns large value Date: Wed, 16 Mar 2005 10:41:06 -0500 Lines: 55 Organization: Cincinnati Electronics X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1437 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1441 NNTP-Posting-Host: 66.117.195.80 Message-ID: <42385392$3@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1110987666 66.117.195.80 (16 Mar 2005 07:41:06 -0800) Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!news.glorb.com!feeder2.on.meganewsservers.com!meganewsservers.com!textfeed1.on.meganewsservers.com!38.119.100.83.MISMATCH!news-out.nntp.be!propagator2-sterling.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail