Jump to content

Get list of sessions users


vbdavie

Recommended Posts

I've spent some time looking for a way to get a list of sessions from the servermodule or mainmodule and can't seem to find anything.

I want to be able to see a list of users that are using the app. So, if 10 people are on-line, then I should be able to see all 10 of their session instances.  Some kind of instance array.

 

Once I have this, I am hoping that I can issue some sort of "LogOut" method to KILL a specific user.

 

Is this possible?

 

Thanks

Davie

Link to comment
Share on other sites

To save the time, I got it from an example

  var
                S : TUniGUISessions;
                U : TUniGUISession;
                i , nr: Integer;
     ASessionList : array of TUniSessionInfoRec;


  begin
     S := UniServerModule.SessionManager.Sessions;
     nr:=S.SessionList.Count;
     S.Lock;
       // Using Lock on session manager should be used with extreme care.
       // We should keep this "Lock" active as short as we can. Session Manager stops working until lock is released.
       // Excessive use of lock/unlock or keeping the lock active for a long period will make uniGUI server slow/unresponsive.
     try
       SetLength(ASessionList, S.SessionList.Count);

       // Here we do a fast copy of list to another array for later use.
       nr:= S.SessionList.Count - 1;
       for i := 0 to nr  do
           begin
           U := S.SessionList;
           ASessionList.ASessionId := U.SessionId;
           ASessionList.AIP        := U.RemoteIP;
           ASessionList.ALastTime  := U.LastTimeStamp;
           end;
     finally
       S.Unlock; // ... and finally don't forget to release lock!
     end;

 

 

  • Like 1
Link to comment
Share on other sites

  • 4 years later...

The same code in C++ Builder, if someone needs it.

	TStringList *lstSessions = new TStringList();
	TUniGUISessions *S = UniServerModule()->SessionManager->Sessions;
	int nr = S->SessionList->Count;

	S->Lock();
	// Using Lock on session manager should be used with extreme care.
	// We should keep this "Lock" active as short as we can. Session Manager stops working until lock is released.
	// Excessive use of lock/unlock or keeping the lock active for a long period will make uniGUI server slow/unresponsive.

	try
	{
	   // Here we do a fast copy of list to another array for later use.
	   for (int i=0; i<nr; i++)
	   {
		   TUniGUISession *U = (TUniGUISession*)S->SessionList->Items[i];
		   lst->Add("SessionId: " + U->SessionId);
		   lst->Add("RemoteIP: " + U->RemoteIP);
		   lst->Add("LastTimeStamp: " + U->LastTimeStamp);
	   }
	}
	__finally
	{
		S->Unlock(); // ... and finally don't forget to release lock!
	}

 

Link to comment
Share on other sites

  • 2 weeks later...
On 10/31/2023 at 3:05 AM, SMARAM said:

The same code in C++ Builder, if someone needs it.

	TStringList *lstSessions = new TStringList();
	TUniGUISessions *S = UniServerModule()->SessionManager->Sessions;
	int nr = S->SessionList->Count;

	S->Lock();
	// Using Lock on session manager should be used with extreme care.
	// We should keep this "Lock" active as short as we can. Session Manager stops working until lock is released.
	// Excessive use of lock/unlock or keeping the lock active for a long period will make uniGUI server slow/unresponsive.

	try
	{
	   // Here we do a fast copy of list to another array for later use.
	   for (int i=0; i<nr; i++)
	   {
		   TUniGUISession *U = (TUniGUISession*)S->SessionList->Items[i];
		   lst->Add("SessionId: " + U->SessionId);
		   lst->Add("RemoteIP: " + U->RemoteIP);
		   lst->Add("LastTimeStamp: " + U->LastTimeStamp);
	   }
	}
	__finally
	{
		S->Unlock(); // ... and finally don't forget to release lock!
	}

 

How to kill a session?

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...