Jump to content

Server Broadcast ALL Other Open Sessions And Queue An fMain AjaxEvent - How


andyhill

Recommended Posts

I am trying to walk all other open sessions and queue an fForm ajaxevent (is the lock preventing it from broadcasting) - How

MainModule
  UniServerModule.BroadCastRefresh(UniSession.SessionID);

procedure TUniServerModule.BroadCastRefresh(SessionID: String);
var
  i: Integer;
  S: TUniGUISessions;
  U: TUniGUISession;
begin

  //////////////////////////////////////////////////////////////////////////////
  S:= SessionManager.Sessions;
  S.Lock;
  try
    for i:= 0 to S.SessionList.Count - 1 do begin
      U:= S.SessionList[i];
      if U.UniMainModule <> nil then begin
        if U.SessionId <> SessionID then begin
          U.AddJS('ajaxRequest(fMain.window, "_RefreshRequired_", []);');
        end; // <> SessionID
      end; // nil
    end; // for
  finally
    S.Unlock;
  end;

end;

 Not Firing.

Link to comment
Share on other sites

On 7/11/2023 at 10:38 PM, andyhill said:

Thanks Sherzod :)

 

Hello,

I am interesting.

Can we get the number of all  opened sessions with web sockets ?

(In classical methode unigui demo sessionlist with s.Lock  sometimes works, sometimes no).

Thx

Link to comment
Share on other sites

On 7/11/2023 at 5:57 AM, Sherzod said:

web sockets.

Hello  Maestro,

Sorry for bypassing this topic.

Can we get the number of all  opened (active) sessions with web sockets ?

(In classical methode : unigui demo "Session List"  sometimes works, sometimes no : if i refresh browser, number grows).

Here is my function :

function TDM_Sessions.Nb_Sessions:cardinal;
//  works elusively
var
  I : Integer;
  S : TUniGUISessions;
  U : TUniGUISession;
  n:integer;

begin
  n:=0;
  S:= UniServerModule.SessionManager.Sessions;

  S.Lock;
  try
    for I := 0 to S.SessionList.Count -1 do
    begin
      U:=S.SessionList[i];

      if (U.UniMainModule as TUniMainModule<>Nil)  // Ghost Sessions
      and (U<>Nil)                                 // Ghost Sessions
      then
        inc(n);
    end;

  finally
    S.Unlock;
  end;

  result:=n;
end;

Thx.

Link to comment
Share on other sites

1 hour ago, Farshad Mohajeri said:

After a while old session will timeout and number will decrease.

Thank you Farshad,

Very hapy to hear you.

I am developping an  inventory mobile unigui application for supermarkets.

This application is sold by number of active sessions (users smatphones).

Example : if customer has two employees, he will buy a licence for maximum 2 actives sessions.

So, it is important to have in live active sessions with accuracy.

Conclusion :

- what is the best way to get in live number of true active sessions ?

- can websokets give this information (a function) ?

Thx

Link to comment
Share on other sites

On 7/13/2023 at 6:04 PM, picyka said:

I already worked in this format, when logging in, I made an insert, when logging out, I killed the record.

how do you handle those who do not log out but only close the browser as soon as they are "finished"?

Link to comment
Share on other sites

On 7/13/2023 at 3:13 PM, Farshad Mohajeri said:

Hi,

It grows because a new session will be created. However, after a while old session will timeout and number will decrease.

@Farshad

Sorry if i come back again.

uniGUIApplication.BroadcastMessage can reach all active (live) sessions. So the new websokets you have coded knows, for sure the total of these active sessions.

If it's not hard, could you add please, a function that would give this number?

n:=GetTotalActiveSessions;

This will simplify many things.

Thx

Link to comment
Share on other sites

  • 3 months later...
On 7/19/2023 at 11:28 PM, Abaksoft said:

@Farshad

Sorry if i come back again.

uniGUIApplication.BroadcastMessage can reach all active (live) sessions. So the new websokets you have coded knows, for sure the total of these active sessions.

If it's not hard, could you add please, a function that would give this number?

n:=GetTotalActiveSessions;

This will simplify many things.

Thx

Hello Farshad,

Hoping all is good.

Any update of this ?

Function GetTotalActiveSessions

With the new websocket

Thx

Link to comment
Share on other sites

  • 1 month later...
  • Administrators
On 10/27/2023 at 11:57 AM, Abaksoft said:

Hello Farshad,

Hoping all is good.

Any update of this ?

Function GetTotalActiveSessions

With the new websocket

Thx

What will be the usage for this function?

In a single application a function can return this value easily because websockets server is embedded in the application, but in a cluster only the actual WebSockets server knows this number.

Link to comment
Share on other sites

  • 3 weeks later...
On 7/15/2023 at 5:37 PM, picyka said:

MainModule event OnDestroy

Humm...

It does'nt work (build 1577).

I came back to standard method (Demo / sessionList).

 

Working with picyka tip

I tried  :

• StandAlone 

• As Service 

• As Hyperserver

When closing the browser, MainModule event OnDestroy does'nt fire. So my session's table can not be upated (deleting current session).

@Farshad :  MainModule OnCloseBrowser Event works only on server side. Not on Client side !

why ?

________

Edited :

i am using intranet SSL

https://192.168.1.11:8077

Tested only with : Google Chrome

 

  • Happy 1
Link to comment
Share on other sites

1 hora atrás, Abaksoft disse:

Humm...

Faz o trabalho (build 1577).

Voltei ao método padrão (Demo / sessionList).

 

Trabalhando com dica picyka

Eu tentei:

• Autônomo

• Como Serviço

• Como Hyperserver

Ao fechar o navegador, O evento MainModule OnDestroy não é acionado. Assim, a tabela da minha sessão não pode ser atualizada (excluindo a sessão atual).

@Farshad: MainModule OnCloseBrowser Event funciona apenas no lado do servidor. Não do lado do cliente!

por que?

 

This is complicated, I already did some tests a while ago, sometimes you have several browser tabs open, and you close the browser directly, and these events do not pass.

Link to comment
Share on other sites

15 hours ago, picyka said:

This is complicated, I already did some tests a while ago, sometimes you have several browser tabs open, and you close the browser directly, and these events do not pass.

 @Picyka   and   @Farshad 

I apologize for my False Alerte.

Maybe a problem in my program.

 

So, I created a new Empty Unigui Project and Tested (writing on an inifile time when closing Sessions) :

• StandAlone 

• As Service 

• As Hyperserver

in SSL mode and without SSL

Both Client and Server Side

 

Results :

1. The good News :   On Desktop Browsers (intranet)

- MainModule OnBeforeDestroy Event :  works fine   

  Don'nt use OnDestroy   

- MainModule OnBrowserClose Event :  works fine !

 

 

2. The Bad News :

On Mobile Bowser (Chrome)  it does'nt fire Events   OnBeforeDestroy  and   OnBrowserClose

This is the problem !  :(

 

 

Link to comment
Share on other sites

Don'nt lost your time.

It's difficult to detect mobile closing browser or tab.

https://stackoverflow.com/questions/30403050/how-to-detect-closing-of-mobile-browser-android-chrome-with-javascript

 

So, to get total opened sessions, use the classical method (unigui \ Demo \ SessionsList).

(Yes, this is valid also for mobile closing tab and browser).

Link to comment
Share on other sites

On 12/2/2023 at 7:24 AM, Farshad Mohajeri said:

It is available, but not public.

@Farshad,

Our Mobile manager inventory system for supermarkets is in production and works fine.

A big thx to marlon's components, unimFsQrCodeScanner  

 

• As we sell the solution with a licence which supports total Active Sessions,

• As we are using classical  SessionList technic (from unigui Demo)

When the total active sessions is reached, and an other user attempt to run the app from its mobile browser, 

he has to wait for 5 min (timeOut session) to run again the app (asking a colleague to close his browser).

it is a bit embarrassing.

 

So, i come back to you :

Would you be kind to open visibility on GetTotal active sessions with embeded websockets ?

This will be the fastest way to get it.

Thx

 

Edited

I have already tried to use @picyka technic, wich works fine on desktop browsers, but not on mobile browsers (as described in a topic above)

Link to comment
Share on other sites

1 hour ago, Abaksoft said:

@Farshad,

Our Mobile manager inventory system for supermarkets is in production and works fine.

A big thx to marlon's components, unimFsQrCodeScanner  

 

• As we sell the solution with a licence which supports total Active Sessions,

• As we are using classical  SessionList technic (from unigui Demo)

When the total active sessions is reached, and an other user attempt to run the app from its mobile browser, 

he has to wait for 5 min (timeOut session) to run again the app (asking a colleague to close his browser).

it is a bit embarrassing.

 

So, i come back to you :

Would you be kind to open visibility on GetTotal active sessions with embeded websockets ?

This will be the fastest way to get it.

Thx

 

Edited

I have already tried to use @picyka technic, wich works fine on desktop browsers, but not on mobile browsers (as described in a topic above)

hi if i can help with any idea.

I'm using per-user limits. Each user can log into the application only once on one device and in one browser tab.

if a user logs in on one device and then logs in with the same user on another device, it will close all other sessions with that user.

for this process, I use some techniques that picuka also mentioned, such as:

1. each user on login is recorded in a table on the server

2. when a user logs in, all records in the table with that user are deleted and then only one record is added (user, device ID, some other unique data about the user)

3. I have a timer in each session that closes it if the user is not active (checks every X ms if the user + device ID (Pos Terminal ID) + other data is in the table)

4. I have added srOnePerIP server limit per session

5. I have added a function that closes the user (logged in user session) if there is no activity (checks every 15 minutes by displaying a message to the user and waits for action (button press) 30 seconds)

This way I limit not the sessions but the number of logged in users that are kept in the server table.

I do this because it is possible to have shadow sessions or not a closed session (a closed tab in the browser takes time, any closed session from the user side needs time to close and as you know this may not reach the server because the connection between them is broken for some reason)!

Link to comment
Share on other sites

1 hour ago, irigsoft said:

hi if i can help with any idea.

Thank you very much  @irigsoft

I really appreciate your help and trust in your method.

But as you can see, all the gymnastic you have done for getting Total Active Sessions (users) in Live, can be done by a simple magic function from websockets.

This is why i have asked Farshad to open this public function.

:)

 

  • Upvote 1
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...