RTC Forums
November 25, 2024, 12:50:08 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: TRtcServerModule.onDisconnect event not execute  (Read 6123 times)
Binh
Guest
« on: July 02, 2010, 05:27:42 AM »

In my application I can't catch TRtcServerModule.onDisconnect event (TRtcHTTPServer.onClientDisconnect executed). How to  catch that ?
Thanks for read !
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #1 on: July 02, 2010, 09:17:01 AM »

TRtcHttpServer component has two disconnect events: OnDisconnect and OnClientDisconnect. TRtcServerModule component only has the OnDisconnect event. There is a big difference between the OnDisconnect and OnClientDisconnect events.

The "OnDisconnect" event will get triggered only if a connection was lost before a complete response could be sent for a request which has already been accepted, which means that request processing could already have started.

If a connection is closed between each request/response cycle, which is considered a normal disconnect and not a loss of connection, only the OnClientDisconnect event will get triggered (available only on the TRtcHttpServer component).

In other words, you will get the OnDisconnect event on the TRtcServerModule component only if a connection would get lost while you are preparing a result for a remote function call on the Server. The purpose of the OnDisconnect event on the TRtcServerModule component is to handle unexpected disconnects while processing requests accepted by the TRtcServerModule component.

You can test this behavior by placing a breakpoint in one of the OnExecute events handled by the TRtcServerModule, making a remote function call from the Client and closing the Client after the breakpoing is reached on the Server. This will result in the connection to get closed while the request is being processed and will result in the OnDisconnect event to get called on the TRtcServerModule component which was processing the request.

On the other hand, if you close or disconnect the Client before it sends a remote function call to the Server or after the Server has responded to the last remote call received, the OnDisconnect event will not be called on the TRtcServerModule because it is not supposed to. Only the OnClientDisconnect event on the TRtcHttpServer component would be called in that case.

I hope this explains it.

Best Regards,
Danijel Tkalcec
Logged
Binh
Guest
« Reply #2 on: July 14, 2010, 03:23:00 AM »

Thanks Danijel Tkalcec,
I'm understand. But I have another little question. I need access to session on event OnClientDisconnect(TRtcHTTPServer) same to  on event OnDisconnect(TRtcServerModule). How to I access it ?.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #3 on: July 14, 2010, 09:08:03 AM »

In order to access Session data from these events, you need to know the Session ID. If you know the Session ID, you can find and lock the Session by using the FindSession method, then you can access its data through the Session property of the TRtcDataServer(Sender) component. You will also need to unlock the Session object afterward, since these events are not supposed to have access to the Session object.

What I'm wondering now is why you want to access Session data from onDisconnect and onClientDisconnect events. The purpose of using Sessions is to keep track of clients even when they are using Proxy Servers and connect to the Server through different physical connections for every request, opening and closing connections as required.

If there is a chance that the same client might be returning to the Server using a different physical connection (which is always possible), I strongly recommend against locking Sessions from OnDisconnect or OnClientDisconnect events because that can get you into a situation where a returning client will try to acquire a lock on its Session while you are keeping a lock on it from the OnDisconnect or OnClientDisconnect event. Since the client will be unable to lock a Session while its lock is held elsewhere, the client would appear "logged out" to the Server.

Best Regards,
Danijel Tkalcec
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #4 on: July 14, 2010, 11:41:29 AM »

I'm not sure if you are aware of this, but the HTTP protocol is Request/Response-based and not Connection-based. Physical connections are still used, but a Client does NOT have to keep a connection open all the time to remain "connected" to the Server. Clients using HTTP could open a connection before sending each Request and close it immediately after receiving a Response, but still remain "connected" (logged in) to the Server. Multiple Clients using HTTP could also be working through a single Proxy Server which could use a single physical connection for a number of different Clients, in which case the Server get requests from all the Clients through a single connection.

By using Sessions, the Server can distinguish between different Clients even when they are all coming from the same physical connection, but a loss of connection after processing a request from some Client does NOT necessarily mean there is a problem with that specific client. It could also mean that there was a problem with the Proxy which was forwarding the request and the Proxy itself or the Client will re-send the request again.

So ... if you wanted to access the Session from the OnDisconnect and OnClientDisconnect events to close it, I would strongly advise against it. Sessions have timeout periods and will be closed by the RTC SDK if the Client will not return to the Server after your specified timeout expires.

Best Regards,
Danijel Tkalcec
Logged
Binh
Guest
« Reply #5 on: July 20, 2010, 09:32:07 AM »

Thanks for deep help,
I'm need access to session for process some information. I had used onSessionClose(TRtcServerModule), but it not execute - maybe I don't understand how to it execute. I known HTTP protocol is  Request/Response-based and not Connection-based, but I still use it same Connection base because some reason.
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #6 on: July 30, 2010, 03:14:52 PM »

OnSessionClose event will be fired when a Session expires (any session, not just sessions locked by the TRtcServerModule component). But, Session expiration is enabled ONLY if at least two clients are using Sessions. In other words, Sessions will NOT expire if you run tests using a single Client.

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.026 seconds with 16 queries.