Normal Topic Disconnect client when idle for a length of time (Read 4352 times)
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Disconnect client when idle for a length of time
Jul 13th, 2009 at 1:43am
Print Post Print Post  
Hi all,

Does anyone have a tip on how to accomplish the following:  what coding technique will determine that a client logon through the Internet has been idle for "X" number of minutes, and thus automatically disconnected ?
  

Larry
Back to top
IP Logged
 
The Cow
YaBB Administrator
*****
Offline



Posts: 2530
Joined: Nov 22nd, 2002
Re: Disconnect client when idle for a length of ti
Reply #1 - Jul 13th, 2009 at 2:35am
Print Post Print Post  
If your intent is to log off inactive users, you can add code to the "universal event" that set as static global variable (declared in Global Code: "stat VarName as int") to the server time using the @TimeInSeconds function. Because this will run every time there is any event, it will log the time of the last event.

Code
Select All
last_event = @TimeInSeconds()
 



Place a call to RunEntryOnInteral in Global Code to kick off your timeout timer. It will call the On Entry Event code for the named element in the interval supplied as an argument in 1/1000ths of a second (i.e.: 1000 = 1 second). Here I am placing the entry code in the "First" element on the Customers sample application's Main Form.

Code
Select All
stat last_event as int

last_event = 0

RunEntryOnInterval(First, 1000)
 



In the On Entry event for "First", place code that checks the current time in seconds against the time last recorded for an event. Don't worry, the On Entry event being kicked off by the timer does not qualify as a "universal event".

Code
Select All
var now_time as int
var delta_time as int

now_time = @TimeInSeconds()
delta_time = now_time - last_event
if(delta_time > 10)
{
	writeln("TIMEOUT: " + delta_time)
}
else
{
	writeln("NO YET: " + delta_time)

}
RunEntryOnInterval(First, 1000)
 



As you can see., my timer checks at one second intervals, this is probably way too fast for your use. You should set the interval out for many minutes, if not hours before you knock a client off the server.

As for knocking the client off the server, should make sure you have closed as much as you can close using automation, then to actually disconnect and shutdown the client, you call ExitSesame().

Please, write this code with the greatest care. Knocking folk off of their connection when they have stepped away, or because your code doesn't take something into consideration, is going to upset your users - especially if they were carefully looking over a form but not actually interacting with it (reading a report and planning to update the form soon, etc...)

Also, be aware that the code above can only work with a form active. The timer callback, the universal event, only operate with a form open. Additionally, I have seen that you may have to initiate the first interval timer by actually entering the named element, placing it in global code by itself is not enough because the form is not necessarily open and active when global code is run.

If your intent is to determine that a user has been kicked off by an external (not sesame) program, like their ISP has timed them out on a dial up line, you probably can't do that using coding (though something really tricky using a server side mass update might be possible, but ill-advised). The Sesame server does attempt, using a heartbeat, to determine if a connection has been severed, but the timeout is very long to avoid knocking off clients with particularly slow connections. The next version of Sesame has a lot of new code for addressing and diagnosing network reliability issues.

The sys internals folk (now, sadly, a division of MS) have some tools that will allow you to see and analyze your network connections on the server, if you are running Windows. Linux comes with such tools right out of the box.
  

Mark Lasersohn&&Programmer&&Lantica Software, LLC
Back to top
IP Logged
 
lksseven
Full Member
***
Offline



Posts: 416
Location: Southwest
Joined: Jan 26th, 2009
Re: Disconnect client when idle for a length of ti
Reply #2 - Jul 14th, 2009 at 5:12am
Print Post Print Post  
Mark,

I appreciate your time and explanations - much obliged.

I will follow your examples, and proceed with care.  Thanks!

Larry
  

Larry
Back to top
IP Logged
 
BWETTLAUFER
Full Member
***
Offline



Posts: 216
Location: Cambridge, Ontario
Joined: Apr 9th, 2010
Re: Disconnect client when idle for a length of time
Reply #3 - Mar 14th, 2022 at 8:35pm
Print Post Print Post  
Just a little bit of thread necromancy here -- I would love some input.

So currently, we've noticed with 55 users on a WAN, and recent updates to MS Windows, programs not touched in a while cause a lag or slowdown in our system, so I am going to put this code to bump any Sesame session not touched in 60 minutes.

My question is -- if I am running a mass udpate that takes more than 60 minutes (I have a few of those), will each time it touches a record count as a universal event?

Next question, if it does count as a universal event, I'm a little worried that a mass update on 50,000 records will hit the server with a 'what time is it Mr Server?' 50,000 times.  Is @timeinseconds() a local command or a server query?

Thanks!
  
Back to top
IP Logged
 
Ray the Reaper
Global Moderator
Members
Lantica Support
*****
Offline


The One & The Only

Posts: 2480
Joined: Aug 20th, 2003
Re: Disconnect client when idle for a length of time
Reply #4 - Mar 15th, 2022 at 3:52pm
Print Post Print Post  
Hey Blair,

Universal Event will not run during the Mass Update.

TimeInSeconds() is a local command.

-Ray
  

Raymond Yoxall Consulting
ray.yoxall@gmail.com
ryoxall@lantica.com
Sesame Applications, Design and Support
Back to top
IP Logged