关闭idHTTPServer上的所有连接可以通过以下步骤实现:
Contexts
属性,该属性包含了当前所有连接的上下文信息。Connection.Disconnect
方法来关闭连接。Contexts.Lock
方法来锁定连接上下文列表,以确保在遍历和关闭连接的过程中不会有其他线程干扰。Contexts.Unlock
方法。以下是示例代码,演示如何关闭idHTTPServer上的所有连接:
procedure CloseAllConnections(idHTTPServer: TIdHTTPServer);
var
i: Integer;
contexts: TList<TIdContext>;
begin
contexts := idHTTPServer.Contexts.LockList;
try
for i := 0 to contexts.Count - 1 do
begin
TIdContext(contexts[i]).Connection.Disconnect;
end;
finally
idHTTPServer.Contexts.UnlockList;
end;
end;
这样,调用CloseAllConnections
函数即可关闭idHTTPServer上的所有连接。
idHTTPServer是Delphi中的一个组件,用于创建HTTP服务器。关闭所有连接可以用于维护服务器或者在需要重启服务器时使用。
领取专属 10元无门槛券
手把手带您无忧上云