TsgcWebSocketHTTPServer › 属性 › SessionList
保存活动 HTTP 会话的列表;读取它以通过代码管理会话,或赋予你自己的列表来控制会话的存储位置。
property SessionList: TIdHTTPCustomSessionList read GetSessionList write SetSessionList;
在服务器激活之前为 nil
读取 SessionList,使用 GetSession、CreateSession 和 CreateUniqueSession 按代码搜索、创建或移除会话。该列表仅在服务器启动时创建,因此在服务器未激活时它为 nil。
当你需要完全控制会话的存储方式时(例如将它们保存在数据库中或在多个服务器之间共享),请指定你自己的列表。从 TIdHTTPDefaultSessionList 派生并重写虚方法 CreateSession;CreateUniqueSession 会在内部调用它,因此唯一的会话 ID 仍会为你生成。该列表必须在服务器激活之前指定,因为底层的 Indy 服务器不允许在运行时替换会话列表。
当你赋值自己的列表时,SessionClass 属性不再生效,因为由你的列表决定要创建哪个类。完整说明参见 Sessions。
type
TMySessionList = class(TIdHTTPDefaultSessionList)
public
function CreateSession(const RemoteIP, SessionID: string)
: TIdHTTPSession; override;
end;
function TMySessionList.CreateSession(const RemoteIP, SessionID: string)
: TIdHTTPSession;
begin
Result := TMySession.CreateInitialized(Self, SessionID, RemoteIP);
SessionList.Add(Result);
end;
oServer.SessionList := TMySessionList.Create(nil);
oServer.Active := true;