Article View: borland.public.cppbuilder.internet.socket
Article #5270Re: How can I send a TBitmap from Client application to Server application
From: Hans Galema
Date: Tue, 28 Sep 2004 12:51
Date: Tue, 28 Sep 2004 12:51
42 lines
2437 bytes
2437 bytes
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.
I did not test this code. I only have my doubts that it will behave
as expected.
Hans.
Technical Details
Message-ID:
<41595d75@newsgroups.borland.com>Path:
arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!stdio!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mailReferences:
<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>Show Full Headers
Complete Article Headers
X-Google-Thread: 11508e,b60555b8e5a57a55 X-Google-Attributes: gid11508e,public X-Google-Language: ENGLISH,ASCII-7-bit Date: Tue, 28 Sep 2004 14:51:10 +0200 From: Hans Galema <dontusethis@dontusethis.nl> User-Agent: Mozilla Thunderbird 0.7 (Windows/20040616) X-Accept-Language: en-us, en MIME-Version: 1.0 Newsgroups: borland.public.cppbuilder.internet.socket Subject: Re: How can I send a TBitmap from Client application to Server application 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> In-Reply-To: <41586e5b$1@newsgroups.borland.com> Content-Type: text/plain; charset=us-ascii; format=flowed Content-Transfer-Encoding: 7bit NNTP-Posting-Host: 129.125.201.248 Message-ID: <41595d75@newsgroups.borland.com> X-Trace: newsgroups.borland.com 1096375669 129.125.201.248 (28 Sep 2004 05:47:49 -0700) Lines: 42 Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news.maxwell.syr.edu!stdio!newsfeed.frii.net!newsfeed.frii.net!news.compaq.com!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail