Jump to content


Photo

What is Session in UniGui?

session

  • Please log in to reply
32 replies to this topic

#1 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 16 February 2016 - 02:06 PM

Hello, guys, professionals! I don't have a lot experience in web development, so I want to ask simple questions!

 

-What is Session in UniGI? Is that some file on the server like in PHP ? Or is that copy of programm, started on the Server?

 

-How to Use it? Basic, popular examples of using it? I know one - to Add JS UniSession.AddJS('alert(''This is message from JS '')');

 

Could you explain basic things about session?

Attached Files

  • Attached File  18.jpg   186.07KB   10 downloads

  • 0

#2 skepsis

skepsis

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 191 posts
  • LocationGreece

Posted 16 February 2016 - 07:05 PM

I'll try to describe it as simple as I can.

When a user loads unigui app on his browser a session is started for this user, let's say as a channel of conmunication. Everything that is placed on your server module let's say a constant is common for all sessions for all users, on the other hand the properties thar are placed on mainmodule are "alive" only for the current session. When a session is restarted mainmodule reinitialized.

That's for a start. You must experiment a little bit for better understanding.

I hope this was helpful a little bit for you
  • 0

#3 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 16 February 2016 - 07:23 PM

So, when session is active (not termiated) i can communicate with Server. Send or Recieve files, variables, streams, constants and so on?


  • 0

#4 skepsis

skepsis

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 191 posts
  • LocationGreece

Posted 16 February 2016 - 07:32 PM

Of course. Session is active according to session timeout you set on mainmodule.
  • 0

#5 skepsis

skepsis

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 191 posts
  • LocationGreece

Posted 16 February 2016 - 07:33 PM

Of course. Session is active according to session timeout you set on mainmodule.
  • 0

#6 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 16 February 2016 - 07:34 PM

Thank you for the answer. I think you are right about experiments! In generall i understand but details... ...only in practice!!!


  • 0

#7 skepsis

skepsis

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 191 posts
  • LocationGreece

Posted 16 February 2016 - 08:11 PM

I believe that at this forum, a lot of people including me had little or not at all experience in web development because we came from delphi world. And now, thanks to Farshad and his team, we create sophisticated web applications. The result came from a lot of experiment with unigui product and of course read almost all posts of the forum, yes "all". As you know my friend "No pain, no gain" :D

 

Regards


  • 1

#8 Farshad Mohajeri

Farshad Mohajeri

    Administrator

  • Administrators
  • 10276 posts

Posted 17 February 2016 - 08:30 AM

We are improving docs. With each new incremental builds you will see a big change in documents.

 

Thanks for your patience!


  • 3

#9 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 17 February 2016 - 09:21 AM

Good news!!! 


  • 0

#10 delphidude

delphidude

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 191 posts
  • LocationNorway

Posted 17 February 2016 - 08:11 PM

This is how I assume things work:

 

When you initiate the app, an instance of mainmodule is created,

and a unique session constant is created and associated with that instance,

and this constant is also stored in the browser.

 

As you go on using the instance, a check is performed for every request,

comparing the browser stored constant with the mainmodule constant,

and as long as these match, the session is considered alive.

 

Also, a session timeout timer is running at the servermodule, and if this

gets triggered, the session constant is cleared, effectively blocking any

further requests from the browser, and the servermodule then reports

the timeout and offers a reload to the browser.

 

After using Unigui for a while, I do not really see such a great need for

documentation. I know it sounds weird, but it is almost a good thing that

you have to work a bit in the beginning, having a somewhat steep learning

curve, because you then learn the stuff in a practical way, and that sticks.


  • 2

#11 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 18 February 2016 - 04:59 AM

Thank you! DelphiDude!!!

 

You must me a genious))) I mean you don't need documentation.

 

But I see the sense in your words - a lot of things are the same like in Delphi and it helps.


  • 0

#12 Mohammed Nasman

Mohammed Nasman

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 165 posts
  • LocationGaza - Palestine

Posted 18 February 2016 - 06:46 AM

In web development sessions has two meaning:

 

1. Session is an instance for the application with unique ID, it's for one users, for one browser (each tab on chrome has new session even if the same user is logged), each session has it's memory and events dedicate to it, and no session will see other sessions data.

 

session usually has a timeout time (usually 20 min), and if user will be idle for this amount of time, the session will be terminated and all data (not saved) will be lost.

 

2. Session object, it's an object dictionary for each session instance, and it could be access within the application for the same (session id only), for example you can use it as

 

Session['MyUser'] := 'ABC', so you can read it from other pages

 

but in UniGui you declare variables inside "TUniMainModule" and it will be access for the same users on all forms.

 

in both cases, if session timeout (expired) all data will be lost.


  • 0

#13 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 18 February 2016 - 07:07 AM

Mohhamed! Thank you for such detailed answer!!!

 

Before asking that - I also thought that its some copy / instance of the programm but I have read some topics of "What is session" for different technologies, like PHP, and decided to ask here.

 

So, session is instance - clear for me, thank you.

 

As for the second point - if i understand correct - lets take real example from Demos 

 

C:\Program Files (x86)\FMSoft\Framework\uniGUI\Demos\Desktop\SessionTimeout

 

We declare in MainModule variable

AllowTerminate : Boolean; 

and call it in Main

procedure TMainForm.UniCheckBox1Click(Sender: TObject);
begin
  UniMainModule.AllowTerminate:=UniCheckBox1.Checked;
end; 

 Is that good example for your 2 point? 

 

And in other instance there will be another variable AllowTerminate - if I understand you correct?

 

And if I want to share some variable beetwen sessions - if I understand correct - I should keep it on the ServerModule? 


  • 0

#14 Mohammed Nasman

Mohammed Nasman

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 165 posts
  • LocationGaza - Palestine

Posted 18 February 2016 - 08:59 AM

Hi elGringo, Glad I help to clear some things :)

 

regarding your question regarding AllowTerminate  variable, this  will effect point 1 & 2, because it will not the let session terminate when it's reach it's time out, it's used to extend the session for another perid of time, look at OnSessionTimeout in UniGUIMainModule:

procedure TUniMainModule.UniGUIMainModuleSessionTimeout(ASession: TObject;
  var ExtendTimeOut: Integer);
begin
  if not AllowTerminate then
  begin
    ExtendTimeOut:=15000;  // extend session for another 15 seconds
  end;
end;

  • 0

#15 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 18 February 2016 - 09:41 AM

I agree, my example is for both 1&2))) Just if it would be any other variable than it will not exist after we will destroy the instance, as I understand.

 

Ok theme is almost clear for me - thank you Mohhamed and All for attention!!!

 

Other details in experiments and practice!


  • 0

#16 Oscar Flor

Oscar Flor

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 140 posts
  • LocationAsuncion

Posted 18 February 2016 - 01:33 PM

Awesome:

 

I don't notice that be can possible to extend Session Timeout before occurs.

 

This could be usefull to stop timeout when a database action is take to long (extract detailed reports),  wating process finishing a so on....

 

Thanks a lot!


  • 0

Oscar Flor
Sebaot Software


#17 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 18 February 2016 - 02:11 PM

Oscar, Mohhamed, Delphidude, Farshad, skepsis, and how do you think - what is normal practice for SessionTimeout Management in real Application?

 

I tested simple Application for 15 hours with this code above and it was working. Server responded the answer.

 

In real Application - how is it better to manage SessionTimeout

 

- to set it to 24 hours for example?

 

-or to set it endless how in the example above?

 

Because on the one hand it's not good when Application Terminated when user is working.

 

On another hand as I understood when user close the tab application terminated automatically.

 

Then endless Session seems to be the best variant?


  • 0

#18 Oscar Flor

Oscar Flor

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 140 posts
  • LocationAsuncion

Posted 18 February 2016 - 02:52 PM

Good I will talk by my experience:

 

Users are a lot of .... people, they arrives on his work place, turn on his computers, log on in the web app, and goes to breakfast, drink terere or cafe, o small talk with the secretary, and when a customer arrives sit down on this place and want o use the web app, and surprise.....a timeout error occurs...and of course they complain.

 

That's because I implement a timer that every 5 mins take a call to the server to do something, sometimes read a database table of messages to search if they are any for the current user o wherever else. This process maintain alive his session for ever.

 

But sometimes the connection to the server is lost by for example for a internet down, normally on a branch on other city. Then a timeout is needed to clean up session temporary files, database connections, a so on.

 

When a user executes a report that takes to long to respond (normally when generate pdf file to publish to) the session must keep alive until finish the generation and ever more.

 

I put a big button to logout to all pages to suggest users to push it when they want to close app, but never use it, always use the red close button from browser windows. Then a timeout process is needed to do in this case. I notice that UniGui now have a event when this occurs.

 

Last thing, you developers must to be very carefull when use database transactions to update data with a crud (database record maintenance). The transaction must start and finish in the same event (buttonOnClick, OnKeyPress, etc.) if you left the transaction active between ajax call probably you wil cry later because user can swear that he update the data, but data is gone from database because never occurs a commit. If a timeout occurs in this time the could be happen.

 

I always be not satisfied with the actual session model of UniGui. I understand that the point is to be closer than Desktop/VCL apps is working but in web world could not be the best model. I never talk with Farshad about this because I think they have more importans things to do and there are more urgents. But I think that in a future of UniGui must have a way to implement a pool of sessions instead of create a session for every user that browse a page.


  • 2

Oscar Flor
Sebaot Software


#19 skepsis

skepsis

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 191 posts
  • LocationGreece

Posted 18 February 2016 - 06:53 PM

Well done Oscar Flor. A real life scenario. I agree with you 100%
  • 0

#20 elGringo

elGringo

    Advanced Member

  • uniGUI Subscriber
  • PipPipPipPip
  • 425 posts

Posted 18 February 2016 - 07:05 PM

Wow! That is very detailed answer, Oscar!!!

 

So, if to assume your practice - best practice will be

 

-keep session alive (by "doing something" with server or maybe with AllowTerminate:=false; like above)

 

-terminate session on Connection down to clean temporary files

 

-to put "false" CloseApp button, and on click not to terminate,  and real termination will be on closing browser tab

 

-to keep transactions in one event

 

Good advices for the beginners!!! Thank you!!!


  • 0





Also tagged with one or more of these keywords: session

0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users