我正在使用一个带有 IdTCPServer 的表单来管理来自带有 AThread.connection.readln/writeln 系统的客户端的字符串。字符串处理有效,这不是问题。
问题是,带有服务器的表单挂起并且不会加载,但它仍然管理所有连接到它的客户端所以它正在运行但它只是不能作为表单工作。 我会猜测它位于阅读线上或其他地方......但我不知道此时此刻我该如何解决这个问题。
请帮忙。
procedure TMonitorFrm.ServerExecute(AThread: TIdPeerThread);
procedure post(PostMessage:string);
begin
try
AThread.Connection.WriteLn(PostMessage);
except
showmessage('Cannot post');
end;
end;
var
ActClient : PClient;
sTemp,
CommBlock,
NewCommBlock,
ReceiverName,
sContent,
sSQL,
sCommand : String;
iCount2,
iCount : Integer;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
begin
if not AThread.Terminated and AThread.Connection.Connected then
begin
CommBlock := AThread.Connection.ReadLn();
ActClient := PClient(AThread.Data);
ActClient.LastAction := Now;
sCommand := copy(CommBlock,0,pos(',',CommBlock)-1); {seperate command}
sContent := copy(CommBlock,pos(',',CommBlock)+1,length(CommBlock)-(pos(',',CommBlock)+1)); {seperate data block}
iCount:= 0 ;
if sCommand = 'Announce' then //SPECIAL
begin
{ Do stuff for this command...}
end
else if sCommand = 'CheckSect' then
{Etcetera...}
procedure TMonitorFrm.FormCreate(Sender: TObject);
var
sCompetitionID : string;
sldb : TSQLiteDatabase;
sltb : TSQLiteTable;
begin
Clients := TThreadList.Create;
Server.Active := True;
AreaPnlList := TComponentList.Create;
SectionPnlList := TComponentList.Create;
Repeat until InputQuery('Competition Select', 'Please type the ID of the competition', sCompetitionID);
iCompetitionID:=StrToInt(sCompetitionID);
OpenDatabase(slDb);
sltb:=slDb.GetTable('SELECT * FROM SectionTable WHERE CompetitionID='+sCompetitionID);
Frame31.CreateSections(sltb,Frame31);
sltb.Free;
CloseDatabase(slDb);
{
This section needs to check the SQLite databases for sections and list them in the display window and makes a drag n drop profile...
}
end;
最佳答案
Indy 使用阻塞套接字。 应该挂起当前线程。要在保持 VCL 线程响应的同时在 VCL 线程中使用 Indy 组件,请在窗体上也放置一个 TIdAntifreeze
组件。 Indy 组件知道该组件并将定期将控制权交给它,以便您的 VCL 线程可以继续处理消息。
关于Delphi 简单 TCP 服务器挂起。表单卡住但服务器继续管理客户端,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2694479/