Thread View: borland.public.cppbuilder.internet.socket
7 messages
7 total messages
Started by Skaarak
Thu, 23 Aug 2007 16:58
Sending BMP over Indy 9
Author: Skaarak
Date: Thu, 23 Aug 2007 16:58
Date: Thu, 23 Aug 2007 16:58
44 lines
2435 bytes
2435 bytes
BDS 2006, Indy 9
I have a TCP Server & Client that connect and talk with each other.
I'm trying to send a BMP from one to the other, but I seem to
be having issues and I was wondering if anyone had any pointers.
So the client seems to connect, and get information over the stream,
but the image that comes across looks like a small box with verticle
lines (like at the end of TV programming at night).
My guess is I'm not quite writing or reading the stream right, but
my experience in this is limited.
Thanks for the help.
-Cory
ps. I did try just copying to a stream and then reading it back from
the stream (same program) and that worked, so I'm assuimg the
data being sent is valid.
----------------------------
SERVER ----------------------------------------------
(In Constructor) sendbmp = new Graphics::TBitmap;
void __fastcall TSDIAppForm::IdTCPServer1Execute(TIdPeerThread *AThread) {
if (AThread->Connection->Connected()) {
TMemoryStream *ms;
ms = new TMemoryStream ();
sendbmp->SaveToStream(ms);
AThread->Connection->WriteStream(ms, true, true, ms->Size);
delete (ms);
}
}
--------------------------
CLIENT ------------------------------------------------
void __fastcall TSDIAppForm::Button3Click(TObject *Sender)
{
TMemoryStream *ms;
ms = new TMemoryStream;
IdTCPClient1->ReadStream(ms, -1, false);
sentbmp->LoadFromStream(ms);
delete ms;
}
Re: Sending BMP over Indy 9
Author: Remy Lebeau (TeamB)
Date: Thu, 23 Aug 2007 18:25
Date: Thu, 23 Aug 2007 18:25
13 lines
1353 bytes
1353 bytes
"Skaarak" <skaarak@NOakamailSPAM.com> wrote in message news:46cdbcc9$1@newsgroups.borland.com... > I'm trying to send a BMP from one to the other, but I seem to > be having issues and I was wondering if anyone had any pointers. On the client side, you are not adjusting the TStream::Position property back to 0 after ReadStream() exits, so there is nothing for TBitmap::LoadFromStream() to load. Gambit
Re: Sending BMP over Indy 9
Author: Skaarak
Date: Thu, 23 Aug 2007 20:12
Date: Thu, 23 Aug 2007 20:12
21 lines
1725 bytes
1725 bytes
"Remy Lebeau (TeamB)" <no.spam@no.spam.com> wrote in message news:46cdd181$1@newsgroups.borland.com... > > "Skaarak" <skaarak@NOakamailSPAM.com> wrote in message > news:46cdbcc9$1@newsgroups.borland.com... > >> I'm trying to send a BMP from one to the other, but I seem to >> be having issues and I was wondering if anyone had any pointers. > > On the client side, you are not adjusting the TStream::Position property > back to 0 after ReadStream() exits, so there is nothing for > TBitmap::LoadFromStream() to load. > Thanks for the thought. I set the position to be 0 after the read stream, and I do have a small (very small) portion of the BMP. Do I need to set the position to 0 after I SaveToStream (from the BMP)? Is my 'ms->Size' the correct value for that portion of the call? -Cory
Re: Sending BMP over Indy 9
Author: Remy Lebeau (TeamB)
Date: Thu, 23 Aug 2007 20:34
Date: Thu, 23 Aug 2007 20:34
25 lines
1839 bytes
1839 bytes
"Skaarak" <skaarak@NOakamailSPAM.com> wrote in message news:46cdea2e$1@newsgroups.borland.com... > I set the position to be 0 after the read stream, and I do > have a small (very small) portion of the BMP. Then you are not sending the full BMP to begin with, or you are not displaying it correctly after recieving it. Also keep in mind that the server code you showed is not thread-safe, so make sure that no other thread is modifying the BMP while it is being stored into the TStream that will be sent. > Do I need to set the position to 0 after I SaveToStream > (from the BMP)? No, because you are setting the AAll parameter of WriteStream() to true, which will send the entire stream. > Is my 'ms->Size' the correct value for that portion of the call? It is fine. Gambit
Re: Sending BMP over Indy 9
Author: Bob Gonder
Date: Fri, 24 Aug 2007 01:30
Date: Fri, 24 Aug 2007 01:30
17 lines
1547 bytes
1547 bytes
Skaarak wrote: >Thanks for the thought. I set the position to be 0 after the read stream, >and I do have a small (very small) portion of the BMP. > AThread->Connection->WriteStream(ms, true, true, ms->Size); > delete (ms); Is WriteStream blocking? If not, then the BMP could be disappearing before it is sent. > IdTCPClient1->ReadStream(ms, -1, false); > sentbmp->LoadFromStream(ms); Is ReadStream blocking, and does it know the size of the incoming data stream? If not, then LoadFromStream could be quitting early?
Re: Sending BMP over Indy 9
Author: Remy Lebeau (TeamB)
Date: Fri, 24 Aug 2007 01:41
Date: Fri, 24 Aug 2007 01:41
17 lines
1378 bytes
1378 bytes
"Bob Gonder" <notbg@notmindspring.invalid> wrote in message news:qpcsc31vrb1easbnjaq1samk5gq4adjcd8@4ax.com... > Is WriteStream blocking? > Is ReadStream blocking Yes. Everything in Indy is blocking. > does it know the size of the incoming data stream? Yes. The parameters Skaarak is passing causes WriteStream() to write the length prior to the data, and ReadStream() to read the length prior to the data. Gambit
Re: Sending BMP over Indy 9
Author: Skaarak
Date: Fri, 24 Aug 2007 21:01
Date: Fri, 24 Aug 2007 21:01
21 lines
1797 bytes
1797 bytes
>> I set the position to be 0 after the read stream, and I do >> have a small (very small) portion of the BMP. > > Then you are not sending the full BMP to begin with, or you are not > displaying it correctly after recieving it. Also keep in mind that the > server code you showed is not thread-safe, so make sure that no other > thread > is modifying the BMP while it is being stored into the TStream that will > be > sent. So I made the code thread safe, and it helped, but it looks like whatever I was doing to show the BMP was failing on the client side. When I went just to a normal BMP everything looked great. Now I'm just running into Canvas drawing errors & out of system resource errors. Whee. Thanks a ton. -Cory
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads