我想知道当前到 Indy 9 TIdTCPServer 的客户端连接数(在 Delphi 2007 上)
我似乎找不到提供此功能的属性。
我尝试在服务器 OnConnect/OnDisconnect 事件上增加/减少计数器,但当客户端断开连接时,该数字似乎永远不会减少。
有什么建议么?
当前活动的客户端存储在服务器的Threads
属性,这是一个TThreadList
。只需锁定列表,读取其Count
属性,然后解锁列表:
procedure TForm1.Button1Click(Sender: TObject);
var
NumClients: Integer;
begin
with IdTCPServer1.Threads.LockList do try
NumClients := Count;
finally
IdTCPServer1.Threads.UnlockList;
end;
ShowMessage('There are currently ' + IntToStr(NumClients) + ' client(s) connected');
end;
在《印地 10》中,Threads
属性被替换为Contexts
财产:
procedure TForm1.Button1Click(Sender: TObject);
var
NumClients: Integer;
begin
with IdTCPServer1.Contexts.LockList do try
NumClients := Count;
finally
IdTCPServer1.Contexts.UnlockList;
end;
ShowMessage('There are currently ' + IntToStr(NumClients) + ' client(s) connected');
end;
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)