Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- From: "Francisco Alvarado" <f.alvarado@xxxxxxxxxxxxxxxxxxxxxxx>
- Date: Wed, 31 Oct 2007 10:41:19 -0600
In some posts I've seen the RawToBytes and BytesToRaw function, but -forgive
my ignorance- I can't find them!
I'm really new to Indy and Sockets comunication and I'm working -with not
much success- in a project using sockets to send information in text and xml
formats.
Using text and FastNet's NMMsg.PostIt() and ClientSocket.Socket.SendData() I
can send a string and receive some response, but I can't use xml format
because I need to send an array of bytes at once.
This VB 6.0 Code works:
length = Len(sData) + 4
IntelFormat = (length / 256)
ParteEntera = Int(IntelFormat)
ParteDecimal = Abs(IntelFormat - ParteEntera)
Char4 = ParteDecimal * 256
sData = Chr(0) + Chr(0) + Chr(ParteEntera) + Chr(Char4) + sData
ReDim ByteArr(Len(sData) - 1)
For i = 1 To Len(sData) Step 1
str = Mid(sData, i, 1)
ByteArr(i - 1) = Asc(str)
Next
FormTools.WinsockXml.SendData (ByteArr)
==============================
This Delphi 5 Code doesn't work
len := Length(Data) + 4;
IntelFormat := (len / 256);
ParteEntera := Trunc(IntelFormat);
ParteDecimal := Abs(IntelFormat - ParteEntera);
Char4 := ParteDecimal * 256;
Data := Chr(0) + Chr(0) + Chr(ParteEntera) + Chr(Char4) + Data;
SetLength(ByteArr, Length(Data) - 1);
for i := 1 to Length(Data) do
begin
s := Data[i];
ByteArr[i - 1] := Ord(s);
end;
with IdTCPClient1 do
begin
Host := Edit3.Text;
Port := StrToInt(Edit4.Text);
Connect;
WriteBuffer(ByteArr, SizeOf(ByteArr), True);
end;
Server receives and empty message and client receives no response...
This is a sample of xml to be send:
<?xml version="1.0" encoding="UTF-8" ?><root><header version="1.0"
eventId="278481" eventName="CodeReceived" ><location HoleNo="11" ABPos="1"
processName="Begining" application="GOLF"/></header><event><CodeReceived
identifier="021"/></event><body><items><item name="typeNo" value="MK"
dataType="8" /></items></body></root>
Any ideas?
Best regards
Francisco Alvarado
.
- Follow-Ups:
- Re: Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- From: Remy Lebeau \(TeamB\)
- Re: Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- From: danny heijl
- Re: Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- Prev by Date: Re: Prof's Threading components
- Next by Date: Re: Prof's Threading components
- Previous by thread: ANN: Power Editor - less than *24 hours left* to get *25% off*!!!
- Next by thread: Re: Sending xml from Indy TCPClient 9.0.18 and Delphi 5
- Index(es):