TsgcWebSocketHTTPServerProperties › SessionList

SessionList Property

List holding the active HTTP sessions; read it to manage sessions by code, or assign your own list to control where sessions are stored.

Syntax

property SessionList: TIdHTTPCustomSessionList read GetSessionList write SetSessionList;

Default Value

nil until the server is activated

Remarks

Read SessionList to search, create or remove sessions by code, using GetSession, CreateSession and CreateUniqueSession. The list is only created when the server starts, so it is nil while the server is not active.

Assign your own list when you need full control over how sessions are stored, for example keeping them in a database or sharing them between several servers. Descend from TIdHTTPDefaultSessionList and override the virtual CreateSession method; CreateUniqueSession calls it internally, so the unique session ID is still generated for you. The list must be assigned before the server is activated, because the underlying Indy server does not allow the session list to be replaced while it is running.

When you assign your own list, the SessionClass property no longer applies, because your list decides which class to create. See Sessions for a full explanation.

Example


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;

Back to Properties