Article View: borland.public.cppbuilder.internet.socket
Article #1571Re: Using ReceiveBuff() from a client socket app?
From: Bob Gonder
Date: Tue, 02 Jan 2007 17:37
Date: Tue, 02 Jan 2007 17:37
39 lines
2178 bytes
2178 bytes
Chris wrote:
>On the client side, you can read the first 4 bytes to get the stream size,
You aren't doing that correctly.
>For the OnRead Event of the Client Socket I call a function
>called DrawImage(). Below is my code:
The rest seems overly convoluted.
But this bit is also very wrong:
>bool __fastcall TForm1::ReceiveStream(TCustomWinSocket *socket, int Size, TStream *Stream)
>{
> void *buffer;
> int NumReceived = socket->ReceiveBuf(buffer, NumToReceive);
Where is ReceiveBuf going to put the data?
>int TForm1::GetStreamSize(TCustomWinSocket *socket)
>{
> int Size = 0;
> void *buffSize = &Size;
> try{
> int NumToReceive = socket->ReceiveLength();
There might be more (or less) than 4 bytes available.
Only read 4 bytes, no more, no less.
> int NumReceived = socket->ReceiveBuf(buffSize, NumToReceive);
int NumReceived = socket->ReceiveBuf( &Size, 4 );
Better would be to have a function (similar to the server send code)
that guarantees that Size bytes have been read from the socket.
Technical Details
Message-ID:
<ku4lp294ehvbh229hj8pdhpdfp31rqa7l0@4ax.com>Path:
arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!tudelft.nl!txtfeed1.tudelft.nl!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mailReferences:
<459a8f2a$1@newsgroups.borland.com>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,41e3cddf77758900 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit From: Bob Gonder <notbg@notmindspring.invalid> Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: Using ReceiveBuff() from a client socket app? Date: Tue, 02 Jan 2007 09:37:44 -0800 Organization: MindSpring Enterprises, Inc. Reply-To: notbg@notmindspring.invalid Message-ID: <ku4lp294ehvbh229hj8pdhpdfp31rqa7l0@4ax.com> References: <459a8f2a$1@newsgroups.borland.com> X-Newsreader: Forte Agent 1.93/32.576 English (American) MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 69.69.87.117 X-Trace: newsgroups.borland.com 1167759424 69.69.87.117 (2 Jan 2007 09:37:04 -0800) Lines: 40 Path: arc1-ca.pugleaf.net!g2news2.google.com!news3.google.com!news.glorb.com!tudelft.nl!txtfeed1.tudelft.nl!feeder.news-service.com!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail