Jump to content

Sessions


dalpiaze

Recommended Posts

I'm developing an applicataion using uniGUI in StandAloneServer mode.

 

I created a Form that shows the sessions of the Web Server clients, using a TListBox.

When the MainModule.OnCreate ocurrs, I add a line "Session xyx started" ... OK

 

If I read the properties of the Sender (TIdHTTPSession), I see only "SessionID" and "RemoteIP"..

 

In current session, I can use the UniSession variable that returns a lot of information..

 

How can I read a TUniGUISession type using an Event or similar, but not in the aspect of the current session, but getting the list of sessions or know the handle of the session that was open?

Link to comment
Share on other sites

  • Administrators

You can retrieve all active sessions using below code:

 

procedure TMainForm.UniButton2Click(Sender: TObject);
var
 I : Integer;
 ASessionList: TList;
 ASession : TUniGUISession;
begin
 UniListBox1.Clear;
 ASessionList:=UniServerModule.SessionManager.Sessions.SessionList.LockList;
 try
for I := 0 to ASessionList.Count-1 do
begin
	ASession := TUniGUISession(ASessionList[i]);
	if not ASession.Terminated then
  	UniListBox1.Items.Add( ASession.UniApplication.RemoteAddress );
end;
 finally
UniServerModule.SessionManager.Sessions.SessionList.UnlockList;
 end;
end;

Link to comment
Share on other sites

OK, thanks. The code works fine.

 

Now I need to catch the Event when the Session starts and stops.

I assigned the events:

 

UniServerModule.SessionManager.Sessions.OnSessionStart := OnSessionStart;
UniServerModule.SessionManager.Sessions.OnSessionEnd := OnSessionEnd;

 

and created the following events:

 

procedure TFrmMon.OnSessionStart(Sender: TIdHTTPSession);
begin
   ListAdd( TUniGUISession(Sender) );
end;

procedure TFrmMon.OnSessionEnd(Sender: TIdHTTPSession);
begin
   ListDel( TUniGUISession(Sender) );
end;

procedure TFrmMon.Add(Secao: TUniGUISession);
begin
   List.Items.Add( Secao.RemoteHost + ' - ' + BrowserToStr(Secao.Browser) );
end;

(...)

 

This code works fine!

 

The problem with this code is that property "Browser" comes "brUnknown" when the session starts

If I read the session again after a few seconds, the property is correctly defined.

 

Is there a way (or another event) to catch the properties of the section when they are loaded ?

 

PS: I tried to do this in another way: adding the properties of the section to my list when the TUniMainModule is created (OnCreate) (that represents a Session).

Works exactly like the prior mode (using SessionManager events)

Link to comment
Share on other sites

  • 3 weeks later...

You can retrieve all active sessions using below code:

 

procedure TMainForm.UniButton2Click(Sender: TObject);
var
 I : Integer;
 ASessionList: TList;
 ASession : TUniGUISession;
begin
 UniListBox1.Clear;
 ASessionList:=UniServerModule.SessionManager.Sessions.SessionList.LockList;
 try
for I := 0 to ASessionList.Count-1 do
begin
	ASession := TUniGUISession(ASessionList[i]);
	if not ASession.Terminated then
  	UniListBox1.Items.Add( ASession.UniApplication.RemoteAddress );
end;
 finally
UniServerModule.SessionManager.Sessions.SessionList.UnlockList;
 end;
end;

 

 

 

Hi

I copy / paste your code in my main form, but I can't compiled my project. I getting always the following compile error. Which unit name should add in "uses" section in my form?

 

Compile errors:

[DCC Error] Main.pas(60): E2003 Undeclared identifier: 'TUniGUISession'

[DCC Error] Main.pas(68): E2029 'THEN' expected but identifier 'Terminated' found

[DCC Error] Main.pas(82): E2029 Statement expected but end of file found

[DCC Error] Main.pas(82): E2029 ';' expected but end of file found

[DCC Fatal Error] Project1.dpr(7): F2063 Could not compile used unit 'Main.pas'

 

 

Thanks and sorry my bad English.

Link to comment
Share on other sites

Hi

I copy / paste your code in my main form, but I can't compiled my project. I getting always the following compile error. Which unit name should add in "uses" section in my form?

 

Compile errors:

[DCC Error] Main.pas(60): E2003 Undeclared identifier: 'TUniGUISession'

[DCC Error] Main.pas(68): E2029 'THEN' expected but identifier 'Terminated' found

[DCC Error] Main.pas(82): E2029 Statement expected but end of file found

[DCC Error] Main.pas(82): E2029 ';' expected but end of file found

[DCC Fatal Error] Project1.dpr(7): F2063 Could not compile used unit 'Main.pas'

 

 

Thanks and sorry my bad English.

 

 

Hi,

 

Uses uniGUIApplication;

 

Regards

Link to comment
Share on other sites

Detailed docs aren't available yet.

 

Mr. Farshad Mohajeri

 

At least may be, about the new properties,functions,procedures etc.

 

for example;

 

TUniForm.Script

ClientEvents(ExtEvents,UniEvents)

TuniServerModule.(CustomCSS,CustomFiles,CustomMeta)

TuniServerModule.ServerMessages(ExceptionTemplate,InvalidSessionMessage and Template,TerminateMessage and template)

etc.

 

Sometimes demos may not be enough for understand. if we can know more things about your product, maybe our contribution to the forum.

Thanks, best regards.

Link to comment
Share on other sites

  • 8 months later...
  • Administrators

Mr. Farshad Mohajeri

 

At least may be, about the new properties,functions,procedures etc.

 

for example;

 

TUniForm.Script

ClientEvents(ExtEvents,UniEvents)

TuniServerModule.(CustomCSS,CustomFiles,CustomMeta)

TuniServerModule.ServerMessages(ExceptionTemplate,InvalidSessionMessage and Template,TerminateMessage and template)

etc.

 

Sometimes demos may not be enough for understand. if we can know more things about your product, maybe our contribution to the forum.

Thanks, best regards.

 

A help system is being prepared. We use doc-o-matic for that

Link to comment
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now
×
×
  • Create New...