cristianotestai Posted August 21, 2011 Posted August 21, 2011 Hi Farshad, I need to identify the moment that sessions are terminated by timeout in server side. I know that the sessions are in control of the server side, and this is exactly what I need. I need for example through the UniSeverModule make a log (with the SessionId) for each session terminated. Is there an event or somewhere in UniServerModule that i can identify it? My reason is to control the sessions that abnormally terminated. Thanks! Quote
dalpiaze Posted August 22, 2011 Posted August 22, 2011 You can do the following: 1. Put a variable "InTime: TDateTime" in TUniMainModule (that represents the session) 2. In "OnCreate" of the MainModule write "InTime := Now;" Then you can catch the OnDestroy of MainModule (that are fired when the session ends), and check if the Session.LastTimeStamp-Session.InTime > DefaultTimeOut. If true, then the session is terminated by timeout. It's an idea that I'm using here. Quote
cristianotestai Posted August 22, 2011 Author Posted August 22, 2011 You can do the following: 1. Put a variable "InTime: TDateTime" in TUniMainModule (that represents the session) 2. In "OnCreate" of the MainModule write "InTime := Now;" Then you can catch the OnDestroy of MainModule (that are fired when the session ends), and check if the Session.LastTimeStamp-Session.InTime > DefaultTimeOut. If true, then the session is terminated by timeout. It's an idea that I'm using here. Hi! I would like to accomplish this control in UniServerModule, which I believe is the right place and this control must exist internally, because the server controls the time of active sessions. Tks for your considerations. Quote
dalpiaze Posted August 22, 2011 Posted August 22, 2011 Hi! I would like to accomplish this control in UniServerModule, which I believe is the right place and this control must exist internally, because the server controls the time of active sessions. Tks for your considerations. Right. In my case, I'm doing this in a TForm that comes visible for the user too. But also works in ServerModule. In your case, you can do the same in ServerModule, reading the events of MainModule's. I suggest create two procedures in Public scope of ServerModule: public procedure NewSession(Session: TUniMainModule); procedure EndSession(Session: TUniMainModule); And then you call this events in OnCreate and OnDestroy of MainModule, filling the "Session" var with the called MainModule: uses uniGUIApplication; type TUniMainModule = class(TUniGUIMainModule) procedure UniGUIMainModuleCreate(Sender: TObject); procedure UniGUIMainModuleDestroy(Sender: TObject); public InTime: TDateTime; Session: TUniGUISession; end; (...) implementation (...) uses ServerModule; procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject); begin InTime := Now; //write the timestamp when the session starts Session := UniSession; //write the address of session ServerModule.NewSession(Self); end; procedure TUniMainModule.UniGUIMainModuleDestroy(Sender: TObject); begin ServerModule.EndSession(Self); end; I hope that is what you looking for. If not, please reply. Thanks. Quote
cristianotestai Posted August 23, 2011 Author Posted August 23, 2011 Right. In my case, I'm doing this in a TForm that comes visible for the user too. But also works in ServerModule. In your case, you can do the same in ServerModule, reading the events of MainModule's. I suggest create two procedures in Public scope of ServerModule: public procedure NewSession(Session: TUniMainModule); procedure EndSession(Session: TUniMainModule); And then you call this events in OnCreate and OnDestroy of MainModule, filling the "Session" var with the called MainModule: uses uniGUIApplication; type TUniMainModule = class(TUniGUIMainModule) procedure UniGUIMainModuleCreate(Sender: TObject); procedure UniGUIMainModuleDestroy(Sender: TObject); public InTime: TDateTime; Session: TUniGUISession; end; (...) implementation (...) uses ServerModule; procedure TUniMainModule.UniGUIMainModuleCreate(Sender: TObject); begin InTime := Now; //write the timestamp when the session starts Session := UniSession; //write the address of session ServerModule.NewSession(Self); end; procedure TUniMainModule.UniGUIMainModuleDestroy(Sender: TObject); begin ServerModule.EndSession(Self); end; I hope that is what you looking for. If not, please reply. Thanks. Hi, dalpiase.. tks for your idea.. i'm using MilliSecondsBetween(dmServerModule.GetData, FSession.LastTimeStamp) > dmServerModule.SessionTimeout) But i'm with a problem.. I need to use my data access components of MainModule before they are destroyed in the closing session. How can I get the moment before the release of objects? I can not use the OnDestroy event because objects are no longer accessible .. an AV occurs, of course .. Any idea? Thanks. Quote
dalpiaze Posted August 24, 2011 Posted August 24, 2011 Cristiano, This is strange, because when OnDestroy of MainModule is fired, the children components has to be still full avaliable, moment that you can free some "on the fly" component and do other things with they. Can you post your relevant code? Quote
cristianotestai Posted August 26, 2011 Author Posted August 26, 2011 Cristiano, This is strange, because when OnDestroy of MainModule is fired, the children components has to be still full avaliable, moment that you can free some "on the fly" component and do other things with they. Can you post your relevant code? Hi, The AV occurred because I was call the procedure to logoff in other Class that made reference to MainModule. Now, in this case, i'm doing the call directly in the MainModule.. Very thanks! Quote
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.