🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.internet.socket
Article #5177

Re: How can I send a TBitmap from Client application to Server application

#5177
From: Mark Jacobs
Date: Tue, 28 Sep 2004 13:43
54 lines
3181 bytes
Gosh you worry too much, Hans. Socket->ReceiveLength() returns the maximum bytes
the receive buffer can hold, if filled up. Subsequent calls return that amount
or less. The last time it will return the remaining bytes, which may be less
than the initial return value. I am sure this code is safe when using Winsock or
Winsock2.
-- 
Mark Jacobs

"Hans Galema" <dontusethis@dontusethis.nl> wrote in message
news:41595d75@newsgroups.borland.com...
| Byanex wrote:
|
| > Mark Jacobs
| >
| > Thank you very much, that code realy works.
|
| That is difficult to believe.
|
|  > | void __fastcall TForm1::ClientSocket1Read(TObject *Sender,
|  > |       TCustomWinSocket *Socket)
|  > | {
|  > |     TMemoryStream *pms=new TMemoryStream();
|  > |     int count=Socket->ReceiveLength();
|  > |     char *Buf=new char[count+9];
|  > |     while (count>0)
|  > |     {
|  > |        Socket->ReceiveBuf(Buf,count); pms->Write(Buf,count);
|  > |        count=Socket->ReceiveLength();
|  > |     }
|  > |     delete Buf; pms->Position=0;
|  > |     Image1->Picture->Bitmap->LoadFromStream(pms);
|  > |     delete pms;
|  > | }
|
| Maybe it works for very small bitmaps. But did you try bitmaps
| with size > 100 KB ?
|
| If you have a large bitmap then ClientSocket1Read() will
| be triggered many times if you just read the bytes
| indicated by ReceiveLength().
|
| In the loop you call ReceiveLength() more often but the same buffer
| for the old Length() is used.
|
| ReceiveLength() in the loop could as well return 0, then you would
| stop for an incomplete image. The rest would then come with a next
| call of ClientSocket1Read.

If it returned 0, then the transaction is complete. Remember, the actual number
of bytes received is the return value of ReceiveBuf.

|
| I did not test this code. I only have my doubts that it will behave
| as expected.
Technical Details
Message-ID: <41596a7c@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!in.100proofnews.com!in.100proofnews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <407e54f8$1@newsgroups.borland.com> <407e66c5@newsgroups.borland.com> <407ec9c7@newsgroups.borland.com> <415080c1$1@newsgroups.borland.com> <415087be$1@newsgroups.borland.com> <41586e5b$1@newsgroups.borland.com> <41595d75@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,b60555b8e5a57a55
X-Google-Attributes: gid11508e,public
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Mark Jacobs" <http://www.jacobsm.com/mjmsg.htm?Borland%20Newsgroup>
Newsgroups: borland.public.cppbuilder.internet.socket
References: <407e54f8$1@newsgroups.borland.com> <407e66c5@newsgroups.borland.com> <407ec9c7@newsgroups.borland.com> <415080c1$1@newsgroups.borland.com> <415087be$1@newsgroups.borland.com> <41586e5b$1@newsgroups.borland.com> <41595d75@newsgroups.borland.com>
Subject: Re: How can I send a TBitmap from Client application to Server application
Date: Tue, 28 Sep 2004 14:43:15 +0100
Lines: 55
Organization: DK Computing
MIME-Version: 1.0
Content-Type: text/plain;
 charset="iso-8859-1"
Content-Transfer-Encoding: 7bit
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: 81.86.186.94
Message-ID: <41596a7c@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1096379004 81.86.186.94 (28 Sep 2004 06:43:24 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!news.glorb.com!in.100proofnews.com!in.100proofnews.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail