Re: Sending xml from Indy TCPClient 9.0.18 and Delphi 5




"Francisco Alvarado" <f.alvarado@xxxxxxxxxxxxxxxxxxxxxxx> wrote in message
news:4728b08d$1@xxxxxxxxxxxxxxxxxxxxxxxxx

In some posts I've seen the RawToBytes and BytesToRaw
function, but -forgive my ignorance- I can't find them!

Those are Indy 10 functions. They don't exist in Indy 9. Indy 10 does not
allow raw memory pointers to be used anymore. A memory buffer has to be
contained inside of a TIdBytes (array of Byte) now. This is because of
Indy's single-source nature. TIdBytes was needed in order to support both
Win32 and .NET without using IFDEFs everywhere.

Using text and FastNet's NMMsg.PostIt() and
ClientSocket.Socket.SendData() I can send a string and
receive some response

You can do the same in Indy. There are manu string-based operations in Indy
so you don't have do work with raw data blocks.

but I can't use xml format

Yes, you can.

I need to send an array of bytes at once.

No, you don't. You can send and receive XML in Indy as String values
instead of byte arrays.

This Delphi 5 Code doesn't work

That is because you are passing the byte array to Indy incorrectly. You are
using a dynamic array, so you must index into the array in order to get the
correct memory address of the data. Also, you must use Length() instead of
SizeOf() to get the size of the data. In other words, change this line:

WriteBuffer(ByteArr, SizeOf(ByteArr), True);

To this instead:

WriteBuffer(ByteArr[0], Length(ByteArr), True);

With that said, you don't need the byte array at all. Indy has many writing
methods available, such as WriteChar(). So you can send the values
individually instead of stuffing them into a byte array first, for example:

len := Length(Data) + 4;
IntelFormat := (len / 256);
ParteEntera := Trunc(IntelFormat);
ParteDecimal := Abs(IntelFormat - ParteEntera);
Char4 := ParteDecimal * 256;
with IdTCPClient1 do
begin
Host := Edit3.Text;
Port := StrToInt(Edit4.Text);
Connect;
WriteChar(0);
WriteChar(0);
WriteChar(ParteEntera);
WriteChar(Char4)
Write(Data);
end;

Alternatively:

len := Length(Data) + 4;
IntelFormat := (len / 256);
ParteEntera := Trunc(IntelFormat);
ParteDecimal := Abs(IntelFormat - ParteEntera);
Char4 := ParteDecimal * 256;
with IdTCPClient1 do
begin
Host := Edit3.Text;
Port := StrToInt(Edit4.Text);
Connect;
OpenWriteBuffer;
try
WriteChar(0);
WriteChar(0);
WriteChar(ParteEntera);
WriteChar(Char4)
Write(Data);
except
CancelWriteBuffer;
raise;
end;
CloseWriteBuffer;
end;


Gambit


.



Relevant Pages

  • Re: Fast string operations
    ... Looping: I thought looping over arrays in managed code was "slow" ... array handling and such. ... The problem with TrimHelper is that it always returns a new string instance. ... The customer perceives this as a memory leak. ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: High Memory Consumption of Classes and Arrays
    ... Only the array itself has overhead. ... memory as a reference type. ... > least consume 40 bytes of memory. ...
    (microsoft.public.dotnet.framework.performance)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.mfc)
  • Re: Fast linked list
    ... > amounts of memory rather than huge chunks of it. ... random insertions into a vector/dynamic array are not as slow ... to cause a cache miss. ... some hard numbers on speed differences between lists and arrays. ...
    (microsoft.public.vc.language)
  • Re: not enough storage... error using GetRows
    ... > array only contained ~150,000 rows. ... It took 19 minutes for GetRows to return (db ... and the prog had consumed 200MB of memory. ... The first one allocates some 180MB, the next two only allocate about 47MB ...
    (microsoft.public.vb.database.ado)