andyhill Posted July 11, 2023 Share Posted July 11, 2023 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. Quote Link to comment Share on other sites More sharing options...
Sherzod Posted July 11, 2023 Share Posted July 11, 2023 Hello @andyhill Use web sockets. Quote Link to comment Share on other sites More sharing options...
andyhill Posted July 11, 2023 Author Share Posted July 11, 2023 Thanks Sherzod 1 Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 13, 2023 Share Posted July 13, 2023 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 Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 13, 2023 Share Posted July 13, 2023 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. Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted July 13, 2023 Administrators Share Posted July 13, 2023 Quote if i refresh browser, number grows Hi, It grows because a new session will be created. However, after a while old session will timeout and number will decrease. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 13, 2023 Share Posted July 13, 2023 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 Quote Link to comment Share on other sites More sharing options...
picyka Posted July 13, 2023 Share Posted July 13, 2023 Perhaps you will need a table to store the data, in the mainModule's Ondestroy, you say that it is no longer active 1 Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 13, 2023 Share Posted July 13, 2023 5 minutes ago, picyka said: Perhaps you will need a table to store the data, in the mainModule's Ondestroy, you say that it is no longer active Thank you picyka. Good idea Quote Link to comment Share on other sites More sharing options...
picyka Posted July 13, 2023 Share Posted July 13, 2023 7 minutes ago, Abaksoft said: Thank you picyka. Good idea I already worked in this format, when logging in, I made an insert, when logging out, I killed the record. 1 Quote Link to comment Share on other sites More sharing options...
chefdackel Posted July 15, 2023 Share Posted July 15, 2023 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"? Quote Link to comment Share on other sites More sharing options...
picyka Posted July 15, 2023 Share Posted July 15, 2023 20 minutes ago, chefdackel said: como você lida com aqueles que não saem, mas apenas fecham o navegador assim que "terminam"? MainModule event OnDestroy 1 Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted July 19, 2023 Share Posted July 19, 2023 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 Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted October 27, 2023 Share Posted October 27, 2023 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 Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted December 1, 2023 Administrators Share Posted December 1, 2023 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. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 1, 2023 Share Posted December 1, 2023 41 minutes ago, Farshad Mohajeri said: In a single application a function can return this value easily because websockets server is embedded in the application Easily with embedded websockets server ? Do we have to develop this function or it already exists ? Quote Link to comment Share on other sites More sharing options...
Administrators Farshad Mohajeri Posted December 2, 2023 Administrators Share Posted December 2, 2023 11 hours ago, Abaksoft said: Easily with embedded websockets server ? Do we have to develop this function or it already exists ? It is available, but not public. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 2, 2023 Share Posted December 2, 2023 2 hours ago, Farshad Mohajeri said: It is available, but not public. Great ! So the 1578 will be eagerly awaited Thx. "What will be the usage for this function?" http://forums.unigui.com/index.php?/topic/23950-server-broadcast-all-other-open-sessions-and-queue-an-fmain-ajaxevent-how/&do=findComment&comment=136755 Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 17, 2023 Share Posted December 17, 2023 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 1 Quote Link to comment Share on other sites More sharing options...
picyka Posted December 17, 2023 Share Posted December 17, 2023 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. Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 18, 2023 Share Posted December 18, 2023 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 ! Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 19, 2023 Share Posted December 19, 2023 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). Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 24, 2023 Share Posted December 24, 2023 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) Quote Link to comment Share on other sites More sharing options...
irigsoft Posted December 24, 2023 Share Posted December 24, 2023 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)! Quote Link to comment Share on other sites More sharing options...
Abaksoft Posted December 24, 2023 Share Posted December 24, 2023 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. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.