Article View: borland.public.cppbuilder.internet.socket
Article #4176Re: TClientSocket ReceiveLength() returns large value
From: Remy Lebeau (TeamB)
Date: Wed, 16 Mar 2005 17:57
Date: Wed, 16 Mar 2005 17:57
62 lines
3939 bytes
3939 bytes
"Gary Johnson" <gjohnson@cinele.com> wrote in message news:42385392$3@newsgroups.borland.com... > i grabbed the code below in a post you suggested. this is the > method i used originally, and it had the same result. Then you did not use it properly to begin with. > 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. If you only call ReceiveLength() once for each triggering of the event, and it gives you a value greater than 0, then that is how many bytes are actually available on the socket for reading. You must read that exact amount from the socket at that moment. No more, no less. Otherwise the reading will become out of synch over time. > you said "Only process packets when your buffer contains full > packets." i don't know what that means. I mean, you are expecting your packets to be a certain size each time. Whenever you read incoming data and buffer it, if the buffer does not contain enough data to constitute a full packet, then you do not process the data. You keep reading more data from the socket and adding it to the buffer. Only when the buffer contains enough data for a full packet, then you process the data for as many full packets as are available, and then remove them from the buffer, keeping the remaining data in the buffer for later processing. > how do i know whether or not i have received a full packet? That is your own responsibility to keep track of. Only you know what kind of data you are actually receiving, so only you know how large each packet is supposed to be. > particularly in my problem case in which i have received > something larger than 1514. The size does not matter. If ReceiveLength() tells you that many bytes are available, than that many bytes really are available, and you must read them all. My guess would be that the server is sending you multiple packets and your code is receiving a single event for them. So, you buffer all of them in one go, and then process as many full packets from the buffer as you can. > int n_received = Socket->ReceiveBuf ( buf, receivelength ); > > > //and n_received == receivelength always! Of course it is. It is supposed to be. The whole point of ReceiveLength() is to specify how many bytes can be read in a single operation without blocking the socket. If your receiving buffer is large enough, then the full data for that event can be read in a sincle call to ReceiveBuf(). If the receiving buffer is not large enough, then you have to call ReceiveBuf() multiple times, reading no more than the total number of bytes specified by ReceiveLength(). Gambit
Technical Details
Message-ID:
<4238735c$1@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!news-in.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> <42385392$3@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 From: "Remy Lebeau \(TeamB\)" <no.spam@no.spam.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> <42385392$3@newsgroups.borland.com> Subject: Re: TClientSocket ReceiveLength() returns large value Date: Wed, 16 Mar 2005 09:57:27 -0800 Lines: 64 X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1409 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1409 NNTP-Posting-Host: 68.69.17.41 Message-ID: <4238735c$1@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1110995804 68.69.17.41 (16 Mar 2005 09:56:44 -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!news-in.newsfeeds.com!in.nntp.be!caladan.landsraad.net!newsgroups.borland.com!not-for-mail