gpt4 book ai didi

delphi - 向所有连接的客户端发送命令

转载 作者:可可西里 更新时间:2023-11-01 02:31:35 24 4
gpt4 key购买 nike

我有一个 TIdHttpServer 我必须保持连接打开才能将一些命令发送回客户端。我想在按下按钮并向所有连接的客户端发送命令时进行迭代。

我该怎么做?

最佳答案

您可以使用 Contexts 属性获取客户端,然后使用每个客户端的 IOHandler 发送消息。

Var
Clients : TList;
i : integer;
begin

if not Assigned(IdTCPServer1.Contexts) then exit;

Clients:=IdTCPServer1.Contexts.LockList;
try
for i := 0 to Clients.Count-1 do
try
TIdContext(Clients[i]).Connection.IOHandler.Write(LBuffer);//LBuffer is a TBytes with the data to send
except
...
end;
finally
IdTCPServer1.Contexts.UnlockList;
end;

end;

关于delphi - 向所有连接的客户端发送命令,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10117691/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com