RTC Forums
May 14, 2024, 04:58:00 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: RtcServerModule1SessionClose  (Read 3545 times)
mr_flash
RTC Expired
*
Posts: 4


« on: April 25, 2017, 08:30:53 AM »

I have problem with this function. I use RTC 7.105 Example from RemoteFunction from QuickStart. When I define
procedure TForm1.RtcServerModule1SessionClose(Sender: TRtcConnection);
When I set bye in Client I works ok but when I do not set bye and I disconect Client without set bye  function TForm1.RtcServerModule1SessionClose is not called. Why ? It complicates my program. What to do to force TForm1.RtcServerModule1SessionClose when Client disconet from Server ?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: April 25, 2017, 09:08:09 AM »

Sessions have nothing to do with connections. Closing a connection does NOT and SHOULD NOT automatically close a Session. The purpose of a Session is to keep persistent information about each Client on the Server between requests, even if the Client closes the connection after every request, uses a proxy to send requests, or sends every request using a different connection.

You can close a Session manually on the Server by using the CloseSession method (as shown in that example Project). If a Session is NOT manually closed, the Session will expire on the Server (after set timeout - provided more than one Client is accessing the Server). If a Client tries to access the Session after it has expired (and was garbage-collected by the Server), the FindSession and HaveSession methods will both return FALSE on the Server, which means that the Session no longer exists.

When using remote functions, the Client is notified automatically about an expired Session the first time it makes a remote function call to the Server using an expired Session ID.

RTC Sessions are used with remote functions when you enable RTC Encryption, because RTC encryption requires the Server to remember the state of each Client between requests, which could be sent using different connections (for example -  through a proxy, where the same connections are usually shared by multiple Clients). RTC Sessions can also be used to store any other information about the Client on the Server, but are otherwise NOT required for RTC remote functions to work.

If you are NOT using Remote Functions with RTC Encryption and you do NOT need to keep persistent information about each Client on the Server between connections, then you do NOT have to use RTC Sessions - even if you are using RTC remote functions.

Best Regards,
Danijel Tkalcec
Logged
mr_flash
RTC Expired
*
Posts: 4


« Reply #2 on: April 25, 2017, 10:25:29 AM »

Ok I know that when I Close connection without 'bye' in this example session will live for 30 second  as Session.KeepAlive:=30;
But after this it shoud Close Session and force RtcServerModule1SessionClose.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: April 25, 2017, 10:51:52 AM »

Sessions which have expired are garbage-collected (Closed) by the same mechanism used for locking and ulocking Sessions for access. If there are no Clients trying to use Sessions on the Server, then Sessions will NOT be garbage-collected (Closed) automatically.

Also, please keep in mind that every access to a Session refreshes its expiration timer. This is why you won't see a Session expiring and closing automatically on the Server if you are using a single Client with a single Session to access the Server. To test how Session expiration and garbage-collection works, you will need at least two Clients, each using a different Session.

The purpose of garbage-collecting and closing expired Sessions is to clear Servers memory from Sessions which probably won't be used anymore, to make space for new Sessions and to ensure that Servers memory will NOT be filled up with Sessions from "dead" Clients. But ... if Sessions are NOT being actively used, then there is no need to waste Servers CPU time to check for possible expired Sessions and/or clean up Session data from memory - which could be expensive, depending on the number of Sessions created and the amount of data stored in each Session.

Best Regards,
Danijel Tkalcec
Logged
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!
Page created in 0.024 seconds with 17 queries.