Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Timeout response
#1
Hello,

I am looking form some info on setting a timeout response.  I in IW 11 it was in server controller, but I have really worried about since then, but now i am looking to implement a nicer error message.  Which Demo for IW 14 or 15 shows this?
Reply
#2
Found the right demo after looking through them again... XIV\CustomizingExceptions
Reply
#3
It seemed straight forward enough, place the files in the templates folder, but its not always showing my IWError.html , IWExcepion.html or IWSessionTimeout.html ..... I test it waiting for few seconds after session timeout and message displays. Wait for a minute to pass and I get the stock Session is invalid - specified session does not exist. Any ideas?
Reply
#4
Hi, try this demo. It's much better to handle SessionTimeout.
Reply
#5
Yes. I think I will add that as well as that will be the easiest and will also avoid a few emais/calls.

Cheers!
Reply
#6
(02-02-2019, 07:10 AM)lfeliz Wrote: Hello,

I am looking form some info on setting a timeout response.  I in IW 11 it was in server controller, but I have really worried about since then, but now i am looking to implement a nicer error message.  Which Demo for IW 14 or 15 shows this?


I found this somewhere in an older forum, not sure who the author was, but this is how I handle session timeouts now and works perfect:

Quote:TIWServerController's SessionTimeout property defines the time of inactivity, in minutes, after which a session is automatically destroyed.

There are at least two problems with this approach:
When a user stops working with your application for a period longer than the timeout, and then returns to the application (for instance, after a lengthy phone call), the browser will happily display Intraweb's timeout screen. You can restart the application, but now all session specific, non-persisted data, is lost...
So you set a longer timeout, let's say, an hour. This doesn't solve the problem above, really, it only makes it less probable. On the other hand, if the user closes the browser window without explicitly closing Intraweb's session (without logging out or performing a similar action), an "active" session is left hanging in Intraweb for the period specified in SessionTimeout. This takes up resources, obviously, but more importantly, may also delay saving user's data (until, for instance, the session is destroyed by Intraweb).
In applications where sessions take up a lot of memory, or use other resources, you can quickly run out of those resources if you have a lot of visitors whose session are left dangling...

Thus, the following solution (based on a comment here):
Set the SessionTimeout to 1 minute.
Add a TIWTimer component to your forms (I use a base form for that).
Set the OnAsyncTimer event to an empty handler.
Set the timer's interval to 20 seconds or so.
This solves problem #1 - the user, as long as he/she has a browser window open, will not get a timeout message.

This helps with problem #2 - the longest period that an active session will not be destroyed is... 1 minute.

The 20 second interval in the timer ensures that a timer will refresh the session 2 to 3 times per minute (modulo networking problems).

Note that each such call sends data to the server, about 2kB worth. So you may need to balance the timeout period with the timer's interval a bit, if that starts to be a problem. And in case of networking problems, you may leave the timer's interval, but raise the session timeout to several minutes.

  type
    TYIWForm = class(TIWAppForm)
      HeartbeatTimer: TIWTimer;
      procedure HeartbeatTimerAsyncTimer(ASender: TObject; AEventParams: TStringList);
    end;
  . . .
  procedure TYIWForm.HeartbeatTimerAsyncTimer(ASender: TObject; AEventParams: TStringList);
  begin
    // Don't do anything,
    // but don't let Delphi's IDE remove this method automatically.
  end;
It doesn't get any simpler than that... :-)
Reply
#7
Hi Ioan. Every Form has a property KeepAlive, just set it to true.
IW can do this for you in the same way as you said to put iwtimer in all forms.
Remove the iwtimer and set KeepAlive := True;
Reply
#8
(02-08-2019, 09:51 AM)Jose Nilton Pace Wrote: Hi Ioan. Every Form has a property KeepAlive, just set it to true.
IW can do this for you in the same way as you said to put iwtimer in all forms.
Remove the iwtimer and set KeepAlive := True;

Hi Jose,

Is there a event handler for the KeepAlive messages? In my implementation I count how many times the HeartbeatTimer timer fires and for some parts of the web application I allow it to time out, something like this:



Code:
procedure TformUserMenu.HeartbeatTimerAsyncTimer(Sender: TObject; EventParams: TStringList);
begin
  StopHeartbeatTimer(HeartbeatTimer);
end;

procedure StopHeartbeatTimer(AHeartbeatTimer: TIWTimer; ACount: integer);
var
  iHeartbeats: integer;
begin
  if ACount > 0 then
    iHeartbeats := ACount
  else
  // a hearthbeat is every 20 seconds, so the timeout its (iHeartbeats * 20) seconds.
  if UserSession.LevelString = 'USER' then
    iHeartbeats := 30
  else if (UserSession.LevelString = 'AGENT') or (UserSession.LevelString = 'COMPANY') then
    iHeartbeats := 45
  else
    Exit; // do not timeout

  if AHeartbeatTimer.Tag > iHeartbeats then
    AHeartbeatTimer.Enabled := false;
  AHeartbeatTimer.Tag := AHeartbeatTimer.Tag + 1;
end;
Reply
#9
More on what Jose said on KeepAlive.

Note that it's the *form* KeepAlive that you are looking for. Don't confuse with the HttpKeepAlive in the servercontroller. Keepalive looks at the session timeout value and sends 3 or 4 messages during that time to keep the session from timing out.

I've used this and it works great, keeping the session active so long as the window is active. Except: On mobile browsers, if the form isn't active it does not want to process the KeepAlive in background like a normal browser (at least that was the case when I last checked a year or so ago).

Dan
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)