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

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: SessionOpen and SessionClose  (Read 4319 times)
HelgeLange
RTC Expired
*
Posts: 100


« on: November 21, 2017, 09:07:48 PM »

Hello Danijel,

I try to change some part of my code to react to SessionOpen and SessionClose on my server side. First of all there are 2, one in the httpServer and another one in RtcServerModule. Which one should I use to see, when I client with a successful connection comes and goes ? I guess it's the ServerModule, right ?

Well, there comes the problem : Sometimes SessionOpen is called, sometimes is not. When I debug, it's always been called. But SessionClose is worse. If I do not debug, it's never called. If I debug, it looks like it's called but half the time it has no event handler assigned in

Code:
procedure TRtcBaseServerModule.Call_SessionClose(Sender: TRtcConnection);
  begin
  if assigned(FOnSessionClose) then
    FOnSessionClose(Sender);
  end;

I placed a breakpoint there. But often it never gets even in debug the session close event.

I placed codesite messages in all 4 events :

Code:
procedure TDMRTC.HttpServerSessionClose(Sender: TRtcConnection);
begin
  CodeSite.Send(csmLevel1, 'HttpServer.SessionClose', Sender.Session.ID);
end;

procedure TDMRTC.HttpServerSessionOpen(Sender: TRtcConnection);
begin
  CodeSite.Send(csmLevel4, 'HttpServer.SessionOpen', Sender.Session.ID);
end;

procedure TDMRTC.sm_LocalServerSessionClose(Sender: TRtcConnection);
begin
  CodeSite.Send(csmLevel1, 'sm_LocalServer.SessionClose', Sender.Session.ID);
end;

procedure TDMRTC.sm_LocalServerSessionOpen(Sender: TRtcConnection);
begin
  CodeSite.Send(csmLevel4, 'sm_LocalServer.SessionOpen', Sender.Session.ID);
end;

and here the result from connect to disconnect, where I should get SessionClose, right ?

Do have have wrong expectations ? Or did I do anything wrong ?

Any ideas or hints ?

Helge
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: November 22, 2017, 08:06:58 AM »

Sessions and connections are two completely independent things. Session expiration is handled during garbage collection, when a Session object is unlocked, but ONLY if at least two Sessions exist. This is because a Session will NOT expire if it has recently been used. The purpose of Session expiration is memory cleanup and is handled loosely. The expiration time is understood as "do not expire before" time and not as "has to expire after" time. There are a number of topics about Sessions on this Forum. You can find them all by using the Search feature of the Forum (top right corner).

What are your expectations and what did you want to do in SessionOpen and SessionClose events?

Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #2 on: November 22, 2017, 02:26:46 PM »

Basically manage my some aspects of our software centralized in a windows service, which is running on a local server.
One aspect are my licensed connections. The client buys a license with 10 workstations. That can means 10 physical workstations or some or all through Remote Desktop (Terminal Server). So if a user goes though logout, there is no problem, as the client signals my service that it is going and I can remove the connection and liberate 1 license.
The problem would be more like when it goes through an abrupt disconnect, like when I close the program with the task manager or the program is stuck for some reason.
Until now I use the connection object you send everytime some message comes, because you also send me that one on disconnect. But I cannot trust that there's always a session object there, can I ? especially on disconnect... Because the easiest way for me would be using your session id to identify a single session. One of the problems there is the following : When a user uses another terminal or another windows session (with Terminal Server), it's another session. If it's using the same IP and Windows User Id, it's the same session and does not consume another license.

I guess, I have to stick with the Sender Object from the calls and use their Pointer as unique identifier... Or you have a better idea  ? Cheesy

Helge
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: November 22, 2017, 04:44:30 PM »

As already said, a Session is completely separate and independent of a connection, which means that you can NOT make assumptions about the state of a Session based on the state of a TCP/IP connection and vice-versa. Please, also keep in mind that Clients using a Proxy will have the same "IP Address" and could also share the same physical connection to the Server, which means that multiple Clients could also be using the same "Sender:TRtcConnection" object.

Anyway ... since RTC SDK does NOT have built-in mechanisms for "License management" and RTC Sessions (or Connections) are NOT really suitable for tracking the number of "currently active" users in real-time, there is no simple answer to your question.

Best Regards,
Danijel Tkalcec
Logged
HelgeLange
RTC Expired
*
Posts: 100


« Reply #4 on: November 22, 2017, 10:23:34 PM »

No problem, I know that RTC is not designed for that, but until now I never had problems with using the Sender as pointer, but I will use a session list of my own for that.

Thanks anyway, Danijel
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.023 seconds with 15 queries.