IdTCP and thread

Giganews Newsgroups
Subject: IdTCP and thread
Posted by:  cxpu (cxpu_…@163.com)
Date: Sun, 22 Jun 2003

I am testing Indy and thread,having a trouble,that is the Time-data from the
server almost was not changed.the program looks as follow:
at the server end:
procedure TServerForm.IdTCPServer1Execute(AThread: TIdPeerThread);
begin
  AThread.Connection.WriteLn('Data from the Server...'+TimeToStr(gettime));
end;

procedure TServerForm.FormCreate(Sender: TObject);
begin
idTCPServer1.Active:=true;
end;

at the Client end:
procedure TForm1.FormCreate(Sender: TObject);
begin
idTCPClient1.Connect(50);
TCPClientRead:=TTCPClientRead.Create(false);//TTCPClientRead =
class(TThread)

end;

unit ReadThreadUnit;

interface

uses
  Classes,Windows;

type
  TTCPClientRead = class(TThread)
  private
  FStr:string;
    { Private declarations }
  procedure UpdateMemo;
  protected
    procedure Execute; override;
  end;

implementation
uses ClientUnit,sysUtils;

procedure TTCPClientRead.Execute;
begin
  { Place thread code here }
  while true do begin
    Fstr:=Form1.IdTCPClient1.ReadLn;
    if Fstr<>'' then
    Synchronize(UpdateMemo) else exit;
    sleep(200);
  end;
end;

procedure TTCPClientRead.UpdateMemo;
begin
  Form1.Memo1.Lines.Add(Fstr);
  Form1.Memo1.Lines.Add('Local Data...'+TimetoStr(gettime));
//  Form1.Memo1.Invalidate;
end;
end.

Any advice?
thanks
cxpu

Replies