Newsgroups : Borland : borland.public.delphi.internet.winsock : 2008 Jan : Re: TIdTCPClient Problem
| Subject: | Re: TIdTCPClient Problem |
| Posted by: | "Remy Lebeau (TeamB)" (no.spam@no.spam.com) |
| Date: | Fri, 25 Jan 2008 10:44:26 |
"F Alvarado" <f.alvarado@brainsoftware.net> wrote in message
news:479a0536$1@newsgroups.borland.com...
> My problem is that when I send two similar messages
> (EventSwitch '-1' and '0') my application just resets.
What do you mean exactly? The application just dies? Is an exception
reported to you?
> with no success. I have an applet with the same code and when I execute it
> works just fine
What applet are you referring to?
> I'm thinking is because of two traslaping calls (too fast)
> but Indy uses blocking sockets!
That would not cause an app to die.
> // Build String
You really should be using a true XML engine for that, such as Delphi's
TXMLDocument component, or any number of available third-party XML
libraries.
> Data := sData;
> 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);
This code looks very familiar. Didn't you post this same code awhile back?
Why are you still doing all of that manually instead of just using
TIdTCPClient's WriteInteger() and Write() methods instead, like was
suggested earlier?
function TForm1.DoPartReceived(EventID, EventSwitch: String): Boolean;
var
tSerialBoxNum, tSerialPalletNum, sData: String;
Errcode, sID, ErrorCode, NextStation, NextStatIdx, NextFuNo,
NextWorkPos, PartState: String;
iSerie, i, len: Integer;
begin
// Build String
//...
LogToFile(sData, 'Write SetPrtRec'); //write in a text file
len := Length(sData) + 4;
LogToFile(sData, 'Write SetPrtRec'); //write in a text file
with IdTCPClient1 do
begin
Disconnect;
Host := AMSHost;
Port := StrToInt(AMSPort2);
ReadTimeout := 1500;
Connect;
try
OpenWriteBuffer;
try
WriteChar(#0);
WriteChar(#0);
WriteInteger(len);
Write(sData);
except
CancelWriteBuffer;
Result := False;
Exit;
end;
CloseWriteBuffer;
end;
Application.ProcessMessages;
try
sData := ReadString(ReadInteger);
LogToFile(sData, 'Read SetPrtRec');
except
lAMSMsg.Text := 'SPR: Read from AMS Fail!';
Raise;
end;
Application.ProcessMessages;
finally
Disconnect;
end;
{
Do something with response (sData)
}
Result := True;
end;
Gambit