System: Dell M1710 (2,16GHz Duo| 2048mb RAM | GeForce Go 7950 GTX 512mb)
IDE: Delphi 2006
Library: Indy 10
I have encountered an irritating problem with the thread that i made to listen for incomming data from my TIdTCPClient.
[pascal]
type
TListenThread = class(TThread)
Crit: TCriticalSection;
procedure ClientReceive(Rec: String);
procedure Execute; override;
constructor Create;
end;
var
Client: TIdTCPClient;
IOHandler: TIdIOHandlerStack;
implementation
{ TListenThread }
procedure TListenThread.ClientReceive(Rec: String);
var
OpCode: TOpCode;
begin
if (Length(Rec) < 2) then Exit;
OpCode[0]:= Rec[1]; //Extract OpCode
OpCode[1]:= Rec[2]; //
Delete(Rec,1,2); //Remove OpCode from Packet Data
HandlerThread.AddPacket(OpCode, Rec);
end;
constructor TListenThread.Create;
begin
inherited Create(False);
end;
procedure TListenThread.Execute;
begin
while (not Terminated) do
begin
if (Client.Connected) then
ClientReceive(Client.IOHandler.ReadLn);
end;
end;
[/pascal]
The problem occurs when i try to send a packet, using another thread. the other thread is using a TCriticalSection when sending, so that it should not "collide", but it does. Sometimes when i send data, the listenthread terminates.
Bookmarks