Newsgroups : Borland : borland.public.delphi.internet.winsock : 2007 Nov : Re: TIdIPMCastServer and Client problem when sending binary data using tIDBytes
| Subject: | Re: TIdIPMCastServer and Client problem when sending binary data using tIDBytes |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Thu, 1 Nov 2007 11:54:49 |
"Sotiris Karanasios" <karanaso@gmail.com> wrote in message
news:4729d2f3@newsgroups.borland.com...
> MStream := TFileStream.Create('d:\0001.png',fmOpenRead);
> MemStream := TMemoryStream.Create;
You don't need the TFileStream. TMemoryStream has its own LoadFromFile()
method:
MemStream := TMemoryStream.Create;
MemStream.LoadFromFile('d:\0001.png');
> MStream.Position := 0;
> MemStream.CopyFrom( MStream, Mstream.Size);
You are not setting the stream's Position back to 0 after CopyFrom() exits.
> MyBuffer := RawToBytes( MemStream, MemStream.Size);
You are passing the memory address of the TMemoryStream object itself, not
the memory address of the data that the stream contains. You need to use
the stream's Memory property for that:
MyBuffer := RawToBytes( MemStream.Memory, MemStream.Size );
Alternatively, use the ReadTIdBytesFromStream() function instead:
ReadTIdBytesFromStream(MemStream, MyBuffer, MemStream.Size);
> Memo1.Lines.Add('BufferSize:'+IntToStr(SizeOf(MyBuffer))+'
TIdBytes is a dynamic array. You can't use SizeOf() to get the size of a
dynamic array. SizeOf() will always return 4 - the size of a pointer. You
have to use Length() instead to get the size of the allocated memory.
> if SizeOf(Adata) > 0 then
Again, you can't use SizeOf() like that. Use Length() instead.
> Now the problem is that I can sent as many text messages as I want.
> Once I press the BinarySend button the MCastClientIPMCastRead
> event is not triggered.
You are not generating the binary data correctly to begin with, so you are
likely crashing the code.
Gambit
none