Jump to content

server side timer in session


vbdavie

Recommended Posts

Depending on users login, i set a different TIMEOUT period.

So, could be 5 minutes or 10 minutes or 30 minutes.

The TuniTimer works GREAT... IF the browser is working properly.

See, the TuniTime DEPENDS on the browser to send the timer events.

I could the number of timer events that I get and then i know "about" how much time has elapsed and then I can TERMINATE the session.

PROBLEM:

Lets pretend that the browser is stuck/hanged/lockedup/frozen ORRRRRRR that the laptop went into SLEEP mode, which means the browser isn't even executing.

That means my TuniTimer will NEVER send an event to the serverside code for my main form. Thus the session will never timeout. I set a big timeout on the servermodule so that I can control how long each session lasts. I set the servertimeoutsecs to 12 houts and then my TuniTimer helps me terminate sessions after a desired period of time. 5/10/30 minutes.

So, if the webbrowser can't send the timer event, how can my mainform get an event on a regular basis WITHOUT relying on the client side to be working?

 

Thanks

Davie

 

Link to comment
Share on other sites

Hello,

Sorry, I didn't really understand your question.
But, your server will not be in hibernation, your web service will always receive events from the client side if they are able to send events, right?

Link to comment
Share on other sites

when the client web browser is stuck/hung/frozen OR the laptop is in hibernate or sleep mode, the webbrowser does NOT send the timer events to my mainform.

I need a timer event for my mainform so that i can do certain things every 10 seconds. EVEN IF the browser is not functioning. So after a certain period of time, i can kill/terminate the session.

 

Thanks

DAvie

Link to comment
Share on other sites

2 hours ago, vbdavie said:

when the client web browser is stuck/hung/frozen OR the laptop is in hibernate or sleep mode, the webbrowser does NOT send the timer events to my mainform.

I need a timer event for my mainform so that i can do certain things every 10 seconds. EVEN IF the browser is not functioning. So after a certain period of time, i can kill/terminate the session.

 

Thanks

DAvie

Davie,

If the browser is not functioning the session will be automatically terminated after a short interval and the mainform will be killed. So there is nothing you need to do to make sure the session is killed if the browser if not working or the laptop has gone to sleep.

Link to comment
Share on other sites

7 hours ago, vbdavie said:

when the client web browser is stuck/hung/frozen OR the laptop is in hibernate or sleep mode, the webbrowser does NOT send the timer events to my mainform.

I need a timer event for my mainform so that i can do certain things every 10 seconds. EVEN IF the browser is not functioning. So after a certain period of time, i can kill/terminate the session.

 

Thanks

DAvie

Hi,

I have simple solution.

1. My session will be closed (on server side) if no user action in X minutes

2. I ask every 15 minutes client to confirm question (Are You there)

2.1. When I ask from user confirmation i wait Y seconds to confirm

2.2 if no answer after Y seconds (browser tab is closed, browser hang on or else) , then server close this session

I hope this can help:

 

 

Link to comment
Share on other sites

Irigsoft;

The TuniTimer REQUIRES that the BROWSER send the timer event. So if the browser is non functional (frozen/hung/asleep/hibernated) then your mainform will never get the timer event :(

 

Norm;

Which server setting controls this "automatically terminated after a short interval"? My hibernated sessions end up going for 24 hours. My session idle timeout is set for 24 hours. In this case, i don't seem to have a way to kill the session earlier.

 

Davie

Link to comment
Share on other sites

33 minutes ago, vbdavie said:

The TuniTimer REQUIRES that the BROWSER send the timer event. So if the browser is non functional (frozen/hung/asleep/hibernated) then your mainform will never get the timer event

 

2 hours ago, irigsoft said:

2. I ask every 15 minutes client to confirm question (Are You there)

2.1. When I ask from user confirmation i wait Y seconds to confirm

2.2 if no answer after Y seconds (browser tab is closed, browser hang on or else) , then server close this session

 

Link to comment
Share on other sites

3 hours ago, vbdavie said:

The TuniTimer REQUIRES that the BROWSER send the timer event. So if the browser is non functional (frozen/hung/asleep/hibernated) then your mainform will never get the timer event

"TuniTimer REQUIRES that the BROWSER send the timer event" - I thing this is not true ! Because if you try to set uniTimer.Chainmode = False then no action will execute. I have on MainForm uniLabel that show every second Date/Time from server. If no server then no label.caption will be changed, this is because action start from server and go to client.

 

Try my proposal and see that is not like You thing.  That is because Server wait Y seconds and close if no action from user

Link to comment
Share on other sites

34 minutes ago, vbdavie said:

yes, irigsoft said he asks a question every 15minutes. That is triggered by a uniTimer event. That means it WONT work, if the browser went dead/asleep.

Right?

 

DAvie

You not understand my logic.

I have 3 time period expired:

1.  Session Ajax request - uniServerMоdule.AjaxTimeOut

2. Session Timeout - uniServerMоdule.SessionTimeout

3. Time to wait answer from client (Y seconds) and then if no answer (If browser is dead) a Server kill session.

   3.1 I have settings how many time for one hour to ask from user answer of "Are You there" ?

   3.2 I have settings how many seconds will wait from this answer before kill session

So try my code and please write results.

uniTimer event is Server Side event, so I don't need answer from client to kill session.

 

I will give you  point 4. Try to save in database Session_ID when open session, then on every X minutes/seconds just kill it !

Link to comment
Share on other sites

1 hour ago, vbdavie said:

Which server setting controls this "automatically terminated after a short interval"? My hibernated sessions end up going for 24 hours. My session idle timeout is set for 24 hours. In this case, i don't seem to have a way to kill the session earlier.

UniServerModule.SessionTimeout this is how many miliseconds server will wait for answer from client. (on client side)

Link to comment
Share on other sites

44 minutes ago, vbdavie said:

That is triggered by a uniTimer event. That means it WONT work, if the browser went dead/asleep.

Because server send ShowMessage with callback, then server can wait client to answer. At this point i set Y seconds to wait from answer, if no answer then server kill session.

 

This works even if the browser tab is closed!

Link to comment
Share on other sites

10 hours ago, vbdavie said:

Norm;

Which server setting controls this "automatically terminated after a short interval"? My hibernated sessions end up going for 24 hours. My session idle timeout is set for 24 hours. In this case, i don't seem to have a way to kill the session earlier.

The SessionTimeout is an integer property in the ServerModule that you can set to any value.

Here is a simple solution I use:

First of all I set a SessionTime value at a low value (e.g. 2 minutes) and I set the uniTimer value at in the Main form, at say 30 seconds. I also create a boolean variable called "ImStillAlive" in the MainModule and set it to True at the start of the session.

When the UniMainModuleSessionTimeout event fires in the MainModule I  check whether the flag "ImStillAlive" flag is true or false. If the flag is true I extend the SessionTimeout by another 2 minutes and set the ImStillAlive flag to false. If the flag has not been reset to true next time the UniMainModuleSessionTimeout event fires I do nothing and let the session die.

Meanwhile the Main form has the responsibility to always reset the ImStillAlive flag to True whenever the uniTimer fires (every 30 secs). If the browser dies the uniTimer will no longer fire and the session will die next time the UniMainModuleSessionTimeout fires.

Simple but reliable.

The UniMainModuleSessionTimeout procedure looks like this:

procedure TdmDB.UniGUIMainModuleSessionTimeout(ASession: TObject;
  var ExtendTimeOut: Integer);
begin
  if bImStillAlive then
  begin
    ExtendTimeOut := iMySessionTimeOut; (e.g. 2minutes)
    bImStillAlive := false;
  end
  else
    //Here we let the session die. So do all the cleanup necessary
    CleaUpThings; //Call a procedure to do some cleanup
end;

Something important you should know:
Whenever the uniTimer fires it restarts the SessionTimeOut count in the ServerModule. So if your uniTimer is permanently enabled and it has an interval value that is lower then the SessionTimeout value then the session will never expire as long as the browser is active. The reason I use the above strategy is because whenever the uniTimer fires I momentarily stop the timer while I do whatever function I created the timer for and then I restart it on completion.

 

Link to comment
Share on other sites

9 hours ago, vbdavie said:

yes, irigsoft said he asks a question every 15minutes. That is triggered by a uniTimer event. That means it WONT work, if the browser went dead/asleep

Davie, just so you understand, Irigsoft’s suggestion is a good solution but it answers a different question, which is: How to detect that the browser is alive but idle because the user is not doing anything.

Depending on what your app is for this might be an issue you’ll need to address at some point.

 

Link to comment
Share on other sites

7 hours ago, Norm said:

How to detect that the browser is alive but idle because the user is not doing anything.

if the user does nothing then i also close the session if no answer of question

My idea is to keep a small amount of sessions active, so if I don't get a response, I terminate that session.
If the user works in the system, each of his actions resets the counter for displaying the message, so the time until the message is displayed starts running when there is no activity

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...