Re: Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- From: "Remy Lebeau \(TeamB\)" <no.spam@xxxxxxxxxxx>
- Date: Wed, 31 Oct 2007 13:30:39 -0700
"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
.
- References:
- Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- From: Francisco Alvarado
- Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- Prev by Date: Re: ZipForge behavior
- Next by Date: Re: ZipForge behavior
- Previous by thread: Re: Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- Next by thread: ANN: Ledger Accounting Update
- Index(es):
Relevant Pages
|