RTC Forums
April 28, 2024, 08:58:41 PM *
Welcome, Guest. Please login or register.

Login with username, password and session length
 
   Home   Help Login Register  
Pages: [1]
  Print  
Author Topic: Session is null when making a call from a web browser  (Read 3440 times)
brian71us
RTC Expired
*
Posts: 15


« on: June 02, 2017, 03:50:46 PM »

Hello,

I've reviewed the topic on accessing a session from a remote procedure call. The code below works properly when I call the method from a client written in Delphi but when calling the method from a web browser then the Session property is nil.

      with sender as TRtcDataServer do
      begin
        if Assigned(Session) then
          Session.asString['User'] := Value;
      end;

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


« Reply #1 on: June 02, 2017, 04:07:14 PM »

Does your JavaScript code send a Session ID to the Server as part of its request? If it does, where does your JavaScript code expect to receive a Session ID from the Server and how is that Session ID sent from the Web Browser to the Server?
Logged
D.Tkalcec (RTC)
Administrator
*****
Posts: 1881


« Reply #2 on: June 02, 2017, 04:52:17 PM »

In a nutshell ...

For the Server to recognize and automatically lock a "Session" after receiving a remote function call from any Client, that Client has to send a Session ID to the Server in the request containing the remote function call and the Server has to know where to look for the Session ID. If the Client does NOT send a Session ID with its request, or if the Session ID is not where the Server expects it, the Server can NOT automatically lock a Session before calling the OnExecute event of a remote function.

In older RTC SDK versions, the Session ID always had to be sent from the Client as part of the 'ID' parameter in the request query (http://myserver.com/myrequest?ID=mySessionID). Starting with RTC SDK v8, you can also use the AutoSessionField property to specify a different field name (it does not have to be 'ID' anymore) and the AutoSessionMode property to define if the Session ID should be sent in the Request Cookie (part of HTTP Header values) or the Request Query (part of the URL).

Additionally, to open a new Session on the Server, the Client either has to send the word 'NEW' (all uppercase) as the Session ID parameter, or ... you need to write a remote function on the Server, which the Client will be calling to initialize a new Session, where you will be using the OpenSession method to open a new Session for that Client.

The alternative is to implement your own Session handling, or ... avoid using Sessions alltogether (keep your Server "stateless") by writing your remote function so that all the information needed to execute each remote function will be sent as parameters of that remote function.

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