procedure TStatusForm.IdTCPUpdateCommands;
var
S: String;
I: Integer;
AStream: TMemoryStream;
ALength: Integer;
AContext: TIdContext;
AClientList: TList;
ATestRecord: TTestRecord;
begin
SetLength(ATestRecord, 3);
ATestREcord[1] := 'Tester';
if not Assigned(IdTCPServer1.Contexts) then Exit;
try
AClientList := IdTCPServer1.Contexts.LockList;
for I:=0 to AClientList.Count-1 do
begin
AContext := TIdContext(AClientList[I]);
try
if AContext.Connection.IOHandler.InputBufferIsEmpty then
AContext.Connection.IOHandler.CheckForDataOnSource(0);
while not AContext.Connection.IOHandler.InputBufferIsEmpty do
begin
S := AContext.Connection.IOHandler.ReadLn;
if S = 'SendMeTheRecord' then
begin
try
AStream := TMemoryStream.Create;
ALength := Length(ATestRecord);
AStream.Position := 0;
AStream.Write(ALength, SizeOf(Integer));
AStream.Write(ATestRecord[0], SizeOf(ATestRecord[0])*ALength);
AContext.Connection.IOHandler.Write(AStream, 0, True); // mit schreiben der Laenge
finally
AStream.Free;
end;
end;
end;
except
on E:
Exception do
AContext.Connection.Disconnect;
end;
end;
finally
IdTCPServer1.Contexts.UnlockList;
end;
end;